简体   繁体   English

CodeIgniter电子邮件发送错误

[英]CodeIgniter email sending error

I am trying to send email with CodeIgniter here is my code 我正在尝试使用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';
            }

    }

but it gives me this type of error 但这给了我这种错误

The following SMTP error was encountered: 110 Connection timed out Unable to send data: AUTH LOGIN Failed to send AUTH LOGIN command. 遇到以下SMTP错误:110连接超时无法发送数据:AUTH LOGIN无法发送AUTH LOGIN命令。 Error: Unable to send data: MAIL FROM: 错误:无法发送数据:MAIL FROM:

from: 从:

The following SMTP error was encountered: Unable to send data: RCPT TO: 遇到以下SMTP错误:无法发送数据:RCPT TO:

to: 至:

The following SMTP error was encountered: Unable to send data: DATA 遇到以下SMTP错误:无法发送数据:DATA

data: 数据:

The following SMTP error was encountered: Unable to send data: User-Agent: CodeIgniter Date: Fri, 29 Jan 2016 06:59:14 +0000 From: "Alex Tester" Return-Path: To: coderjack9@gmail.com Subject: =?iso-8859-1?Q?Email_Test?= Reply-To: "alextester1003@gmail.com" X-Sender: alextester1003@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <56ab0dc2af7ad@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; 遇到以下SMTP错误:无法发送数据:User-Agent:CodeIgniter日期:2016年1月29日,星期五,06:59:14 +0000发件人:“ Alex Tester”返回路径:至:coderjack9@gmail.com主题: =?iso-8859-1?Q?Email_Test?==回复至:“ alextester1003@gmail.com” X-发件人:alextester1003@gmail.com X-Mailer:CodeIgniter X-优先级:3(普通)邮件ID: <56ab0dc2af7ad@gmail.com> Mime版本:1.0内容类型:multipart / alternative; boundary="B_ALT_56ab0dc2af809" This is a multi-part message in MIME format. boundary =“ B_ALT_56ab0dc2af809”这是MIME格式的多部分消息。 Your email application may not support this format. 您的电子邮件应用程序可能不支持此格式。 --B_ALT_56ab0dc2af809 Content-Type: text/plain; --B_ALT_56ab0dc2af809内容类型:文本/纯文本; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Testing the email class. charset = iso-8859-1 Content-Transfer-Encoding:8位测试电子邮件类。 --B_ALT_56ab0dc2af809 Content-Type: text/html; --B_ALT_56ab0dc2af809内容类型:text / html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Testing the email class. charset = iso-8859-1 Content-Transfer-Encoding:quoted-printable测试电子邮件类。 --B_ALT_56ab0dc2af809-- Unable to send data: . --B_ALT_56ab0dc2af809--无法发送数据:。

The following SMTP error was encountered: Unable to send email using PHP SMTP. 遇到以下SMTP错误:无法使用PHP SMTP发送电子邮件。 Your server might not be configured to send mail using this method. 您的服务器可能未配置为使用此方法发送邮件。

 $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();

Note: the mail cannot sent localhost. 注意:邮件无法发送localhost。 if your try live sites. 如果您尝试直播网站。

User this 用这个

$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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM