如何在代码Igniter中发送电子邮件。以下代码中的错误是什么

时间:2014-11-10 07:27:22

标签: javascript jquery

<?php  
class Hello extends CI_Controller  {

    public function __construct()
    {
        parent::__construct();  
        $this->load->library('email'); // load the library
    }
    function index()  {
        $this->sendEmail();  
    }
    public function sendEmail()
    {
        $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 25,
        'smtp_user' => 'suman5571@gmail.com', // change it to yours
        'smtp_pass' => 'not real password', // change it to yours
        'mailtype' => 'html',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
        );

        $message = '';
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n" );
        $this->email->from('suman5571@gmail.com'); // change it to yours
        $this->email->to('jagdeep.think360@gmail.com');// change it to yours
        $this->email->subject('Resume from JobsBuddy for your Job posting');
        $this->email->message($message);
        if($this->email->send())
        {
            echo 'Email sent.';
        }
        else
        {
            show_error($this->email->print_debugger());
        }
    }
}
?>

1 个答案:

答案 0 :(得分:0)

不要忘记更改smtp主机,端口必须是465

<?php  
    class Hello extends CI_Controller  {

        public function __construct()
        {
            parent::__construct();  
            $this->load->library('email'); // load the library
        }
        function index()  {
            $this->sendEmail();  
        }
        public function sendEmail()
        {
       $config = Array(
        'protocol' => 'smtp',
       'smtp_host' => 'ssl://smtp.gmail.com',
       'smtp_port' => 465,
       'smtp_user' => 'xxx@gmail.com', // change it to yours
       'smtp_pass' => 'xxx', // change it to yours
       'mailtype' => 'html',
       'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
        );

            $message = '';
            $this->load->library('email', $config);
            $this->email->set_newline("\r\n" );
            $this->email->from('suman5571@gmail.com'); // change it to yours
            $this->email->to('jagdeep.think360@gmail.com');// change it to yours
            $this->email->subject('Resume from JobsBuddy for your Job posting');
            $this->email->message($message);
            if($this->email->send())
            {
                echo 'Email sent.';
            }
            else
            {
                show_error($this->email->print_debugger());
            }
        }
    }
    ?>