PHPMailer SMTP连接错误
在过去的几个小时里,我一直在想如何让PHPMailer SMTP连接错误,php,email,phpmailer,Php,Email,Phpmailer,在过去的几个小时里,我一直在想如何让phpMailer工作。我总是出错。这是我的密码: <?php $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->
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主机(尽管您声明了变量$Host
)。通过以下方式进行设置:
$mail->host = $host;
感谢@Rikesh的提醒,$port
也是同样的情况
旁注:我注意到你使用gmail.com作为回复邮件,但你的SMTP服务器不是gmail。这可能会导致某些电子邮件服务器将您的电子邮件放入垃圾邮件/垃圾邮件文件夹。尝试添加以下内容:
$mail->Mailer = "SMTP"; // SMTP Method
请参阅此链接,尝试更改端口号
$port = 587;
到
并检查您收到的新错误,我相信您不会再次收到SMTP连接错误
使用SSL:
$mail->SMTPSecure='ssl';//启用TLS加密,也接受'ssl'
$mail->Port=465;//ssl
在php文件中添加以下内容:
$mail->SMTPOptions=array(
“ssl”=>数组(
“验证对等方”=>false,
'verify_peer_name'=>false,
“允许自签名”=>true
)
);
在myaccount.gmail.com
登录和安全
具有帐户访问权限的应用
设置允许安全性较低的应用
打开
您是否尝试使用本地主机上的smtp?这是您使用SMTPDebug=1
获得的所有信息?您是否使用托管Web服务器?可能防火墙正在阻止端口25。如果您可以通过ssh进行连接,请尝试将您的服务器smtptelnet
并查看发生了什么。您需要将host
($host)和port
($port)分配给phpmailer对象。是否尝试将SMTPsecure从ssl更改为tls<代码>$mail->SMTPSecure='tls'嘿,伙计,谢谢你的回答,但我试过了,但它不起作用,同样的错误。已尝试从WAMP和WebServer远程登录SMTP服务器吗?@Mukil OP已声明$mail->IsSMTP();//通过SMTP发送
。此外,您提供的链接不是官方文档。
$port = 465;