我正在嘗試使用PHPMailer在我的網站上創建一個聯繫表單。我在設置時遇到了一些麻煩。我正在嘗試使用G-mail作爲我的smtp主機。我想知道是否有人可以幫助解決這個問題?PHPMailer無法正常工作:無法發送消息
這是我的郵件代碼:
<?php
require("class.phpmailer.php");
require("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 467;
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "workingpassword"; // SMTP password
$mail->From = "[email protected]";
$mail->FromName = "Mailer";
$mail->AddAddress("[email protected]", "Josh Adams");
$mail->AddAddress("[email protected]"); // name is optional
$mail->AddReplyTo("[email protected]", "Information");
$mail->WordWrap = 50; // set word wrap to 50 characters
// $mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
// $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$mail->IsHTML(true); // set email format to HTML
$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. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
錯誤消息:
Message could not be sent.
Mailer Error: The following From address failed: [email protected]
很難說它爲什麼不起作用。你嘗試過'$ mail-> SMTPDebug = 1;' –
是的,我有。這是它顯示的錯誤:SMTP - >錯誤:無法連接到服務器:無法找到套接字傳輸「ssl」 - 您忘記配置PHP時啓用它嗎? (12640394) – AnchovyLegend