gpt4 book ai didi

PHPMailer SMTP 连接错误

转载 作者:搜寻专家 更新时间:2023-10-31 21:10:27 24 4
gpt4 key购买 nike

在过去的几个小时里,我一直在努力弄清楚如何让 phpMailer 正常工作。我不断收到错误。这是我的代码:

<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "******@gmail.com"; // SMTP username
$mail->Password = "******"; // SMTP password
$host = "smtp.mandrillapp.com";
$port = 587;
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug = 1;
$webmaster_email = "****@gmail.com"; //Reply to this email ID
$email= $email; // Recipients email ID
$name= $name; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "University of Life Experiences";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "ULE";
$mail->Body = $message; //HTML Body
$mail->AltBody = $message; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

这是我收到的错误:

SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. Mailer Error: SMTP connect() failed.

我尝试过许多不同的 SMTP 服务器,包括 Gmail,但我总是收到类似的连接失败错误。

请帮忙,我已经尝试了许多其他的 phpMailer 示例代码,它们都存在相同的问题。如果有人可以推荐任何其他有用的 PHP 邮件程序。我没有使用内置的 mail() 函数的原因。

最佳答案

您没有设置 SMTP 主机(尽管您声明了变量 $host )。通过以下方式设置:

$mail->host = $host;

感谢@Rikesh 提醒,$port 也是如此。

旁注:我注意到您使用 gmail.com 作为回复电子邮件,但您的 SMTP 服务器不是 gmail。这可能会导致某些电子邮件服务器将您的电子邮件放入垃圾邮件/垃圾文件夹。

关于PHPMailer SMTP 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21088062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com