2016-01-29 250 views
1

我试图用笨发送电子邮件这里是我的代码笨电子邮件发送错误

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

      // Set your email information 
      $from = array('email' => '[email protected]', 'name' => 'Your Name'); 
      $to = array('[email protected]'); 
      $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'; 
      } 

    } 

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

The following SMTP error was encountered: 110 Connection timed out Unable to send data: AUTH LOGIN Failed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:

from:

The following SMTP error was encountered: Unable to send data: RCPT TO:

to:

The following SMTP error was encountered: Unable to send data: 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: [email protected] Subject: =?iso-8859-1?Q?Email_Test?= Reply-To: "[email protected]" X-Sender: [email protected] X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <[email protected]> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_56ab0dc2af809" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_56ab0dc2af809 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Testing the email class. --B_ALT_56ab0dc2af809 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Testing the email class. --B_ALT_56ab0dc2af809-- Unable to send data: .

The following SMTP error was encountered: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

回答

0
$this->load->library('email'); 
    $this->load->library('user_agent');  
    $this->email->from([email protected]); 
    $this->email->to([email protected]); 
    $this->email->cc([email protected]); 
    $this->email->subject('sub');$this->email->message($messages); 
$this->email->send(); 

注:邮件无法发送本地主机。如果你试试活网站。

+0

我活的服务器上尝试这种 –

0

用户这个

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