Send email from codeigniter

Environment

  • Codeigniter 3.0.1
  • PHP5.5


HTML

<?php echo validation_errors(); ?>
<form method="post" action="/questionnaire/mail_sender">
    <div class="form-group">
    <label for="lastname" class="col-sm-offset-1 col-xs-4 control-label">lastname</label>
        <div class="col-md-3 col-xs-7">
            <input type="text" class="form-control input-sm" name="lastname" id="lastname" placeholder="姓">
        </div>
    </div>
    <div class="form-group">
        <label for="firstname" class="col-sm-offset-1 col-xs-4 control-label">firstname</label>
        <div class="col-md-3 col-xs-7">
            <input type="text" class="form-control input-sm" name="firstname" id="firstname" placeholder="名">
        </div>
    </div>
    <div class="form-group">
        <label for="email" class="col-sm-offset-1 col-xs-4 control-label">email</label>
        <div class="col-md-3 col-xs-7">
            <input type="text" class="form-control input-sm" name="email" id="email" placeholder="sample@example.com">
        </div>
    </div>
    <div class="form-group">
        <label for="taste" class="col-sm-offset-1 col-xs-4 control-label">taste level</label>
        <label class="radio-inline">
            <input type="radio" name="taste" value="1"/> 1
        </label>
        <label class="radio-inline">
            <input type="radio" name="taste" value="2"/> 2
        </label>
        <label class="radio-inline">
            <input type="radio" name="taste" value="3"/> 3
        </label>
        <label class="radio-inline">
            <input type="radio" name="taste" value="4"/> 4
        </label>
        <label class="radio-inline">
            <input type="radio" name="taste" value="5"/> 5
        </label>
    </div>
    <div class="form-group">
        <label for="hospitality" class="col-sm-offset-1 col-xs-4 control-label">hospitality level</label>
        <label class="radio-inline">
            <input type="radio" name="hospitality" value="1"/> 1
        </label>
        <label class="radio-inline">
            <input type="radio" name="hospitality" value="2"/> 2
        </label>
        <label class="radio-inline">
            <input type="radio" name="hospitality" value="3"/> 3
        </label>
        <label class="radio-inline">
            <input type="radio" name="hospitality" value="4"/> 4
        </label>
        <label class="radio-inline">
            <input type="radio" name="hospitality" value="5"/> 5
        </label>
    </div>
    <div class="form-group">
        <label for="other" class="col-sm-offset-1 col-xs-4 col-sm-4 control-label">other check point</label>
            <div class="col-md-5 col-xs-8">
                <textarea id="other" cols="50" rows="10" class="form-control input-sm" name="other"></textarea>
            </div>
        </div>
    </div>
    <input type="submit" class="btn btn-default center-block">submit</button>
</form>


PHP

<?php
class xxx extends CI_controller {
   public function mail_sender()
    {
        $message = $this->input->post('lastname') . "\n";
        $message .= $this->input->post('firstname') . "\n";
        $message .= $this->input->post('email') . "\n";
        $message .= $this->input->post('taste') . "\n";
        $message .= $this->input->post('hospitality') . "\n";
        $message .= $this->input->post('other');

        $config = Array(
            'protocol' => 'smtp',
            //'mail_path' => 'ssl://smtp.gmail.com', // gmail do not work
            'smtp_host' => 'smtp.mail.yahoo.co.jp',
            //'smtp_host' => "smtp.gmail.com",
            'smtp_port' => 587,
            //'smtp_port' => 465, // port 465 do not work
            'smtp_user' => 'xxx@yahoo.co.jp',
            'smtp_pass' => 'xxx',
            'smtp_timeout' => '30',
            //'mailtype'  => 'text',
            //'smtp_crypto' => 'ssl',
            'charset'   => 'utf-8'
        );
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        //$this->email->initialize($config);

        $this->email->from('xxx@yahoo.co.jp', 'email_name');
        $list = array('xxx@gmail.com', 'xxx2@gmail.com');
        $this->email->to($list);
        $this->email->subject('receive email from codeigniter');
        $this->email->message($message);
        if ($this->email->send())
        {
            echo 'return TRUE';
        } else {
            echo 'return FALSE';
            echo $this->email->print_debugger();
        }
    }