PHPMailer SMTP连接错误 [英] PHPMailer SMTP connection error

查看:68
本文介绍了PHPMailer SMTP连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试弄清楚最近几个小时如何使phpMailer正常工作.我不断收到错误消息.这是我的代码:

I've been trying to figure out how to get phpMailer to work for the last few hours. I keep getting errors. Here is my code:

<?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错误:无法连接到服务器:(0)SMTP connect()失败.邮件错误:SMTP connect()失败.

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

我尝试了包括Gmail在内的许多不同的SMTP服务器,并且总是遇到类似的错误,提示无法连接.

I have tried many different SMTP servers including Gmail and I always get a similar error about failing to connect.

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

Please help, I have tried many other phpMailer example codes all with the same issue. If anyone can recommend any other PHP mailing programs that would be useful. The reason I am not using the inbuilt mail() function.

推荐答案

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

You didn't set the SMTP Host ( though you declare the variable $host ). Set it via:

$mail->host = $host;

感谢@Rikesh提醒,$port也是这种情况.

Thanks @Rikesh for reminding, $port is also the same case.

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

Side Note: I noticed you use gmail.com as reply email but your SMTP server is not gmail. This may cause some email servers to put your email to spam / junk folder.

这篇关于PHPMailer SMTP连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆