[請益] phpmailer error

看板PHP作者 (eeswd)時間9年前 (2016/02/02 11:10), 編輯推噓4(402)
留言6則, 4人參與, 最新討論串1/1
大家新年快樂 小弟利用phpmailer練習發信 ,網頁架設在XAMPP SMTP是利用gmail發信 host=smtp.gmail.com, port=587 一直無法排除此error 2016-02-02 02:52:19 SMTP ERROR: Failed to connect to server: (0) 2016-02-02 02:52:19 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed. 利用終端機查看 telnet smtp.gmail.com 587 也正常連線 Trying 173.194.72.108... Connected to gmail-smtp-msa.l.google.com. Escape character is '^]'. 220 smtp.gmail.com ESMTP c13sm6188756pat.8 - gsmtp 想請問有沒有其他解決辦法 謝謝。 以下是code; <?php require('PHPMailer/PHPMailerAutoload.php'); $host = 'smtp.gmail.com'; $port = 587; $mail = new PHPMailer; //SMTP連線 $mail->IsSmtp(); $mail->Host = $host; $mail->Port = $port; $mail->SMTPSecure = "ssl"; //Gmail 通訊協定走SSL $mail->SMTPDebug = 2; $mail->SMTPAuth = true; $mail->Username = '自己的gmail信箱'; $mail->Password = '自己的gmail密碼'; //寄收件 $mail->setFrom('shanyuan1313@gmail.com','mailer'); $mail->CharSet = 'utf-8'; $mail->WordWrap = 72; $mail->AddAddress('shanyuan1313@gmail.com'); //信件內容 $mail->isHTML(true); $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body <b>in bold!</b>'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.25.105 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1454382630.A.C68.html

02/02 11:30, , 1F
ssl有開嗎
02/02 11:30, 1F

02/02 12:13, , 2F
有! 在php.ini開了
02/02 12:13, 2F

02/02 14:39, , 3F
port 改用465 看看,為啥是設587 ?
02/02 14:39, 3F

02/02 15:05, , 4F
587是TLS ssl是 465@@
02/02 15:05, 4F

02/03 09:38, , 5F
port 465
02/03 09:38, 5F

02/03 10:20, , 6F
謝謝 更改port之後又去Gmail設定帳號兩步驗證>成功寄出
02/03 10:20, 6F
文章代碼(AID): #1Mi1ucne (PHP)
文章代碼(AID): #1Mi1ucne (PHP)