【急救】使用Zend_Mail構建郵件送信表單,smtp有有關問題

來源:互聯網
上載者:User
【急救】使用Zend_Mail構建郵件送信表單,smtp有問題
今天寫了一段代碼,使用Zend_Mail構建郵件送信表單,程式始終運行不成功,我懷疑是我的smtp配置的存在問題,實際運行時
$smtp = new Zend_Mail_Transport_Smtp("smtp.gmail.com",
array(
'port' => '25',
'auth' => 'login',
'username' => [email protected]',
'password' => 'XXXXX'
));
username,password均使用真實的可用的郵箱,其各位兄弟幫忙看看問題在哪裡,3Q
整體代碼如下:



郵件送信


郵件送信Zend_Mail



function encode($str){
return mb_convert_encoding($str, "gb2312","auto");
}
if($_POST['submit'] != null){
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
$smtp = new Zend_Mail_Transport_Smtp("smtp.gmail.com",
array(
'port' => '25',
'auth' => 'login',
'username' => [email protected]',
'password' => 'XXXXX'
));
Zend_Mail::setDefaultTransport($smtp);

$mail = new Zend_Mail();
$mail->addTo($_POST['to']);
$mail->setForm("[email protected]",encode("田家"));
$mail->setSubject(encode($_POST['subject']));
$mail->setBodyHtml(encode($_POST['body']));
$attach = $mail->createAttachment(file_get_contents($_FILES['fl']['tmp_name']));
$attach->type = $_FILES['fl']['type'];
$attach->filename = $_FILES['fl']['name'];
$mail->send();
print("郵件發送成功!");
}
?>




------解決方案--------------------
SMTP連接埠錯誤,GMAIL的連接埠並不是25,參考GMAIL官方說明:

配置其他郵件用戶端說明

標準說明:

在 Gmail 中啟用 POP。操作完成後不要忘記點擊儲存更改。
將您的用戶端配置為與以下設定匹配:
內送郵件 (POP3) 伺服器 - 需要 SSL:pop.gmail.com
使用 SSL:是
連接埠:995
發送郵件 (SMTP) 伺服器 - 需要 TLS 或 SSL:smtp.gmail.com(使用身分識別驗證)
使用身分識別驗證:是
TLS/STARTTLS 的連接埠:587
SSL 的連接埠:465
帳戶名稱:您的完整電子郵件地址(包括 @gmail.com 或 @your_domain.com)
電子郵件地址:您的電子郵件地址([email protected] 或 [email protected]_domain.com)
密碼:您的 Gmail 密碼
------解決方案--------------------
array(
'port' => '25',
'auth' => 'login',
'username' => [email protected]',
'password' => 'XXXXX'
));


修改為:

PHP code
array('port' => '587','auth' => 'login','username' => [email protected]','password' => 'XXXXX'));
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.