国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHPMailer使用Gmail來發送郵件的連接smtp服務器錯誤

2024-05-04 21:57:19
字體:
來源:轉載
供稿:網友

我們在使用PHPMailer使用Gmail來發送郵件的連接smtp服務器錯誤提示:smtp error could not connect to smtp host !了,這個是因為extension=php_openssl.dll未開啟導致的哦。

使用的PHPMailer版本:5.2.1,以下是PHPMailer的example文件夾里給出的:test_gamil_basic.php的部分代碼,代碼如下:

  1. $mail = new PHPMailer();  
  2.     $body = file_get_contents('contents.html'); //$body = $_POST['body'];  
  3.     $body = eregi_replace("[]",'',$body);  
  4.     $mail->IsSMTP(); // telling the class to use SMTP  
  5.     $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)  
  6.     // 1 = errors and messages  
  7.     // 2 = messages only  
  8.     $mail->SMTPAuth = true; // enable SMTP authentication  
  9.     $mail->SMTPSecure = "ssl"// sets the prefix to the servier  
  10.     $mail->Host = "smtp.gmail.com"// sets GMAIL as the SMTP server or ssl://smtp.gmail.com  
  11.     $mail->Port = 465; // set the SMTP port for the GMAIL server  
  12.     $mail->Username = "yourusername@gmail.com"// GMAIL username  
  13.     $mail->Password = "yourpassword"// GMAIL password  
  14.     $mail->SetFrom('name@yourdomain.com''First Last');  
  15.     $mail->AddReplyTo("name@yourdomain.com","First Last");  
  16.     $mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";  
  17.     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"// optional, comment out and test  
  18.     $mail->MsgHTML($body);  
  19.     $address = "whoto@otherdomain.com";  
  20.     $mail->AddAddress($address"John Doe");  
  21.     $mail->AddAttachment("images/phpmailer.gif"); // attachment  
  22.     $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment  
  23.     if(!$mail->Send()) {  
  24.     echo "Mailer Error: " . $mail->ErrorInfo;  
  25.     } else {  
  26.     echo "Message sent!";  
  27.     } 

按照這個例子給出的代碼操作,我遇到了以下錯誤:

提示您 smtp error could not connect to smtp host !的錯誤提示,google了下,發現是需要開啟PHP的openssl擴展:

extension=php_openssl.dll //去掉最前面的分號,重啟apache或nginx服務器。

HoHo~成功發送。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云阳县| 荔浦县| 阳高县| 建水县| 固安县| 满城县| 天镇县| 西华县| 西宁市| 保德县| 武城县| 泗阳县| 义马市| 西平县| 固安县| 广元市| 芦溪县| 天长市| 南涧| 道孚县| 安岳县| 保康县| 库尔勒市| 商南县| 临澧县| 博客| 建平县| 佛山市| 蒙山县| 永城市| 偏关县| 乐昌市| 和硕县| 宁夏| 峨眉山市| 浮梁县| 吉隆县| 海阳市| 湖南省| 上饶县| 贞丰县|