提问者:小点点

CodeIgniter电子邮件发送错误


我试图用CodeIgniter发送电子邮件,这是我的代码

function sendmail()
    {
            // Set SMTP Configuration
            $emailConfig = array(
               'protocol' => 'smtp',
                'smtp_host' => 'TLS://smtp.googlemail.com',
                'smtp_port' => 587,
                'smtp_user' => 'email@gmail.com',
                'smtp_pass' => '******',
                'mailtype'  => 'html',
                'charset'   => 'iso-8859-1'
            );

            // Set your email information
            $from = array('email' => 'frommail@gmail.com', 'name' => 'Your Name');
            $to = array('mymail@gmail.com');
            $subject = 'Your gmail subject here';

            $message = 'Type your gmail message here';
            // Load CodeIgniter Email library
            $this->load->library('email', $emailConfig);

            // Sometimes you have to set the new line character for better result
            $this->email->set_newline("rn");
            // Set email preferences
            $this->email->from($from['email'], $from['name']);
            $this->email->to($to);

            $this->email->subject($subject);
            $this->email->message($message);
            // Ready to send email and check whether the email was successfully sent

            if (!$this->email->send()) {
                // Raise error message
                show_error($this->email->print_debugger());
            }
            else {
                // Show success notification or other things here
                echo 'Success to send email';
            }

    }

但它给了我这种类型的错误

遇到以下SMTP错误:110连接超时无法发送数据:身份验证登录无法发送身份验证登录命令。错误:无法发送数据:邮件发件人:

发件人:

遇到以下SMTP错误:无法发送数据:RCPT到:

致:

遇到以下SMTP错误:无法发送数据:数据

数据:

遇到以下SMTP错误:无法发送数据:User-Agent:CodeIgniter日期:Fri,29 Jan2016 06:59:14 0000来自:"Alex Tester"返回路径:到:coderjack9@gmail.com主题:=?ISO-8859-1?Q?Email_Test?=Reply-To:"alextester1003@gmail.com"X-Sender:alextester1003@gmail.comX-Mailer: CodeIgniter X-优先级: 3(正常)消息ID:

遇到以下SMTP错误:无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。


共2个答案

匿名用户

 $this->load->library('email');
  $this->load->library('user_agent');    
  $this->email->from(from@gmail.com);
  $this->email->to(to@gmail.com);   
  $this->email->cc(cc@gmail.com); 
   $this->email->subject('sub');$this->email->message($messages);   
 $this->email->send();

注意:邮件无法通过本地主机发送。如果您尝试使用live站点。

匿名用户

用户本

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.

$result = $this->email->send();