PHPmailer 中的SMTP Connect() 故障排除
簡介
簡介
解決方案
要解決此問題,請按照以下步驟操作:
確保啟用「開啟對不太安全的應用程式的存取”選項。
<code class="php">$mail->Host = "ssl://smtp.gmail.com"; $mail->Port = 465;</code>
修改程式碼以使用連接埠587 上的連接埠587 上的連接埠587 上的連接埠587 TLS 而不是連接埠465 上的SSL。取代以下行:
<code class="php">$mail->Host = 'smtp.gmail.com'; $mail->Port = 587;</code>
範例程式碼
<code class="php">require "class.phpmailer.php"; $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only $mail->SMTPAuth = true; // turn on SMTP authentication $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail $mail->SMTPAutoTLS = false; $mail->Host = 'smtp.gmail.com'; $mail->Port = 587; $mail->Username = "[email protected]"; // SMTP username $mail->Password = "mypassword"; // SMTP password $webmaster_email = "[email protected]"; //Reply to this email ID $email="[email protected]"; // Recipients email ID $name="My Name"; // Recipient's name $mail->From = $webmaster_email; $mail->FromName = "My Name"; $mail->AddAddress($email,$name); $mail->AddReplyTo($webmaster_email,"My Name"); $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML $mail->Subject = "subject"; $mail->Body = "Hi, This is the HTML BODY "; //HTML Body $mail->AltBody = "This is the body when user views in plain text format"; //Text Body if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }</code>範例程式碼這是修改後的程式碼:透過實施這些更改,您應該能夠使用PHPmailer 成功發送電子郵件。
以上是如何修復 PHPmailer 中的「Mailer 錯誤:SMTP connect() 失敗」?的詳細內容。更多資訊請關注PHP中文網其他相關文章!