[英]Error in sending email in codeigniter
我正在使用以下配置通過php郵件功能發送郵件:
function sendInvoiceEmail() {
獲取客戶電子郵件
$recieverEmail = xyz@test.com; //Valid Email ID
$recieverName = xyz;
創建電子郵件配置數組
$emailConfig = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'abc@abc.com', //Valid Email ID
'smtp_pass' => 'password', //Valid password
'mailtype' => 'html', //text or html
'charset' => 'iso-8859-1',
);
設置您的電子郵件信息
$from = array('email' => 'abc@abc.com', 'name' => 'Testing');
$to = array('email' => $recieverEmail, 'name' => $recieverName);
$subject = "Test Mail for Invoice ";
$message = "Test Message for Invoice";
加載CodeIgniter電子郵件庫
$this->load->library('email', $emailConfig);
$this->email->initialize($emailConfig);
有時您必須設置換行符才能獲得更好的結果
$this->email->set_newline("\r\n");
設置電子郵件首選項
$this->email->from($from['email'], $from['name']);
$this->email->to($to['email'], $to['name']);
$this->email->subject($subject);
$this->email->message($message);
准備發送電子郵件並檢查電子郵件是否已成功發送
if ($this->email->send()) {
return true;
} else {
show_error($this->email->print_debugger());
}
}
我有PHP 5.3.9版本和wampserver,但出現以下錯誤:
An Error Was Encountered
The following SMTP error was encountered: 52770504 Unable to find the socket
transport "ssl" - did you forget to enable it when you configured PHP?
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: Thu, 27 Dec 2012 16:50:28
+0530 From: "Invoice Tester" Return-Path: To: df@df.kl Subject: =?iso-8859-1?Q?Test_Mail_for_Invoice_?= Reply-To: "sujit.singh@xpointers.com" X-Sender: sujit.singh@xpointers.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <50dc2efca4149@xpointers.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_50dc2efca4160" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_50dc2efca4160 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Test Message for Invoice --B_ALT_50dc2efca4160 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Test Message for Invoice --B_ALT_50dc2efca4160--
Unable to send data: .
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to
使用此方法發送郵件。
嘗試將“ smtp_host”更改為“ smtp.gmail.com ”
嘗試檢查SSL錯誤:
從該錯誤看來,您的PHP版本可能未使用ssl進行編譯。
跑:
<?php
phpinfo();
?>
並檢查“配置命令”是否具有“ --with-openssl = / usr”之類的內容。 另外,還要檢查“已注冊的流套接字傳輸”部分中是否列出了ssl。
我知道wampserver,PHP擴展中有設置,因此如果您使用wampserver,則可以執行以下步驟:
1)轉到WampSever托盤圖標
2)轉到PHP擴展
3)搜索php_openssl
4)如果未選中,則將其標記為選中( php_openssl
)
否則,您可以參考邁克爾的答案:)
希望對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.