无法使用 CodeIgniter 的电子邮件库发送电子邮件
Cannot send email using CodeIgniter's email library
我正在尝试使用 CodeIgniter 的电子邮件库发送电子邮件。这是我写的代码。
$email_config = array(
'protocol' => 'smtp',
'smtp_host' => ' ssl://smtp.gmail.com',
'smtp_port' => '465',
'smtp_user' => 'shamir.towsif@gmail.com',
'smtp_pass' => '**********',
'mailtype' => 'html',
'newline' => "\r\n",
'charset' => 'iso-8859-1',
"wordwrap" => true
);
$this->CI->load->library('email', $email_config);
$this->CI->email->from('shamir.towsif@gmail.com', 'invoice');
$this->CI->email->to('shamir.towsif@gmail.com', "User");
$this->CI->email->subject('Invoice');
$this->CI->email->message('Test');
$this->CI->email->send();
echo $this->CI->email->print_debugger();
错误:这是我遇到的错误。
The following SMTP error was encountered: 0 php_network_getaddresses:
getaddrinfo failed: Name or service not known 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: Sun, 21 Jun 2015 05:52:56 +0600 From: "invoice" Return-Path: To:
shamir.towsif@gmail.com Subject: =?iso-8859-1?Q?Invoice?= Reply-To:
"shamir.towsif@gmail.com" X-Sender: shamir.towsif@gmail.com X-Mailer:
CodeIgniter X-Priority: 3 (Normal) Message-ID:
<5585fcd8c63f7@gmail.com> Mime-Version: 1.0 Content-Type:
multipart/alternative; boundary="B_ALT_5585fcd8c643b" This is a
multi-part message in MIME format. Your email application may not
support this format. --B_ALT_5585fcd8c643b Content-Type: text/plain;
charset=iso-8859-1 Content-Transfer-Encoding: 8bit Test
--B_ALT_5585fcd8c643b Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Test
--B_ALT_5585fcd8c643b-- 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. User-Agent: CodeIgniter Date: Sun, 21 Jun 2015 05:52:56 +0600
From: "invoice" Return-Path:
To: shamir.towsif@gmail.com Subject:
=?iso-8859-1?Q?Invoice?= Reply-To: "shamir.towsif@gmail.com" X-Sender: shamir.towsif@gmail.com X-Mailer:
CodeIgniter X-Priority: 3 (Normal) Message-ID:
<5585fcd8c63f7@gmail.com> Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5585fcd8c643b"
This is a multi-part message in MIME format. Your email application
may not support this format.
--B_ALT_5585fcd8c643b Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
Test
--B_ALT_5585fcd8c643b Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Test
--B_ALT_5585fcd8c643b--
问题:我以前可以发邮件。然后我重新安装了我的 os 和 lamp 服务器,现在我不能。我做错了什么?
我在 CI 中使用 sendmail 发送电子邮件。在使用发送邮件之前,您必须在 CI 中进行一些配置。
首先,转到 system/libraries/Email.php 并更改以下内容
class CI_Email {
var $useragent = "CodeIgniter";
var $mailpath = "/usr/sbin/sendmail"; // Sendmail path
var $protocol = "sendmail"; // mail/sendmail/smtp
var $smtp_host = "mail.blah-blah.com"; // SMTP Server.
.....
}
然后我做了一个发送邮件的方法。
public function send_mail($email, $subject, $message){
//$this->load->library( 'email' );
$this->email->from( 'no-reply@blah-blah.com', 'blah-blah.com' );
$this->email->to( $email);
$this->email->subject( $subject );
$this->email->message( $message );
$this->email->send();
echo $this->email->print_debugger();
}
就是这样。您现在可以使用 send_mail
方法发送电子邮件。
我正在尝试使用 CodeIgniter 的电子邮件库发送电子邮件。这是我写的代码。
$email_config = array(
'protocol' => 'smtp',
'smtp_host' => ' ssl://smtp.gmail.com',
'smtp_port' => '465',
'smtp_user' => 'shamir.towsif@gmail.com',
'smtp_pass' => '**********',
'mailtype' => 'html',
'newline' => "\r\n",
'charset' => 'iso-8859-1',
"wordwrap" => true
);
$this->CI->load->library('email', $email_config);
$this->CI->email->from('shamir.towsif@gmail.com', 'invoice');
$this->CI->email->to('shamir.towsif@gmail.com', "User");
$this->CI->email->subject('Invoice');
$this->CI->email->message('Test');
$this->CI->email->send();
echo $this->CI->email->print_debugger();
错误:这是我遇到的错误。
The following SMTP error was encountered: 0 php_network_getaddresses: getaddrinfo failed: Name or service not known 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: Sun, 21 Jun 2015 05:52:56 +0600 From: "invoice" Return-Path: To: shamir.towsif@gmail.com Subject: =?iso-8859-1?Q?Invoice?= Reply-To: "shamir.towsif@gmail.com" X-Sender: shamir.towsif@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <5585fcd8c63f7@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_5585fcd8c643b" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_5585fcd8c643b Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Test --B_ALT_5585fcd8c643b Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Test --B_ALT_5585fcd8c643b-- 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. User-Agent: CodeIgniter Date: Sun, 21 Jun 2015 05:52:56 +0600 From: "invoice" Return-Path: To: shamir.towsif@gmail.com Subject: =?iso-8859-1?Q?Invoice?= Reply-To: "shamir.towsif@gmail.com" X-Sender: shamir.towsif@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <5585fcd8c63f7@gmail.com> Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5585fcd8c643b"
This is a multi-part message in MIME format. Your email application may not support this format.
--B_ALT_5585fcd8c643b Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
Test
--B_ALT_5585fcd8c643b Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Test
--B_ALT_5585fcd8c643b--
问题:我以前可以发邮件。然后我重新安装了我的 os 和 lamp 服务器,现在我不能。我做错了什么?
我在 CI 中使用 sendmail 发送电子邮件。在使用发送邮件之前,您必须在 CI 中进行一些配置。
首先,转到 system/libraries/Email.php 并更改以下内容
class CI_Email {
var $useragent = "CodeIgniter";
var $mailpath = "/usr/sbin/sendmail"; // Sendmail path
var $protocol = "sendmail"; // mail/sendmail/smtp
var $smtp_host = "mail.blah-blah.com"; // SMTP Server.
.....
}
然后我做了一个发送邮件的方法。
public function send_mail($email, $subject, $message){
//$this->load->library( 'email' );
$this->email->from( 'no-reply@blah-blah.com', 'blah-blah.com' );
$this->email->to( $email);
$this->email->subject( $subject );
$this->email->message( $message );
$this->email->send();
echo $this->email->print_debugger();
}
就是这样。您现在可以使用 send_mail
方法发送电子邮件。