日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Php错误邮件提示linux,linux下phpmailer发送邮件出现SMTP ERROR: Failed to connect to server: (0)错误...

發(fā)布時間:2023/12/15 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Php错误邮件提示linux,linux下phpmailer发送邮件出现SMTP ERROR: Failed to connect to server: (0)错误... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在作項目的過程當中,后期客戶提出了發(fā)送郵件的需求,既然客戶有需求,那么沒啥說的,上唄。php

通過網(wǎng)上的通常資料查找,PHPMailer這個插件貌似用起來不錯,那就從github clone一份下來,下載連接是PHPMailer。html

官當demo以下:固然相關的配置要換成你本身的linux

//Create a new PHPMailer instance

$mail = new PHPMailer;

//Tell PHPMailer to use SMTP

$mail->isSMTP();

//Enable SMTP debugging

// 0 = off (for production use)

// 1 = client messages

// 2 = client and server messages

$mail->SMTPDebug = 2;

//Set the hostname of the mail server

$mail->Host = 'smtp.qq.com';

//$mail->Host = 'smtp.163.com';

//Set the SMTP port number - likely to be 25, 465 or 587

$mail->Port = 465;

$mail->SMTPSecure = "ssl";

//$mail->SMTPAuth = false;

//$mail->SMTPSecure = false;

//Whether to use SMTP authentication

$mail->SMTPAuth = true;

//Username to use for SMTP authentication

$mail->Username = 'xxxxxxx@qq.com';

//$mail->Username = 'raincowl@163.com';

//Password to use for SMTP authentication

//$mail->Password = 'lingshuan008';

$mail->Password = 'password';

//Set who the message is to be sent from

//$mail->setFrom('raincowl@163.com', 'fromuser');

$mail->setFrom('xxxxxxx@qq.com', 'fromuser');

//Set an alternative reply-to address

//$mail->addReplyTo('raincowl@163.com', 'First Last');

$mail->addReplyTo('xxxxxxx@qq.com', 'First Last');

//Set who the message is to be sent to

$mail->addAddress('yyyyyyy@qq.com', 'John Doe');

//Set the subject line

$mail->Subject = 'PHPMailer SMTP test';

//Read an HTML message body from an external file, convert referenced images to embedded,

//convert HTML into a basic plain-text alternative body

//$mail->msgHTML(file_get_contents('contents.html'), __DIR__);

$mail->msgHTML('hello,body!');

//Replace the plain text body with one created manually

$mail->AltBody = 'This is a plain-text message body';

//Attach an image file

//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors

if (!$mail->send()) {

echo 'Mailer Error: ' . $mail->ErrorInfo;

} else {

echo 'Message sent!';

}

首先本地windows下,發(fā)送成功,很happy,那就放上linux上試下,一運行,出現(xiàn)git

SMTP ERROR: Failed to connect to server: (0)

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

而后各大技術(shù)論壇查資料;首先檢查linux服務器上的openssl和sockets已經(jīng)開啟,fsockopen函數(shù)也沒有禁用,郵箱的smtp服務也已經(jīng)開啟,依然仍是不行。至于有一種說法將smtp換成SMTP,是可以發(fā)送成功,后來查看下源碼,發(fā)現(xiàn)這種只是經(jīng)過sendmail發(fā)送的,不是smtp。而后,直接在linux上ping smtp.qq.com,telnet? smtp.qq.com 465都沒什么問題,但是依然發(fā)送報上述的錯誤,后來查看官網(wǎng)資料,發(fā)現(xiàn)下面一段代碼github

$mail->SMTPOptions = array(

'ssl' => array(

'verify_peer' => false,

'verify_peer_name' => false,

'allow_self_signed' => true

)

);

就猜想了是否是本身的ssl認證沒有經(jīng)過,將這段代碼加上以后,神奇的事情發(fā)生了,郵件發(fā)送成功。windows

到此,問題圓滿解決。服務器

若有疑問,能夠留言。app

轉(zhuǎn)載請注明出處!socket

總結(jié)

以上是生活随笔為你收集整理的Php错误邮件提示linux,linux下phpmailer发送邮件出现SMTP ERROR: Failed to connect to server: (0)错误...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。