2014-01-13 133 views
3

我一直在试图弄清楚如何让phpMailer在过去的几个小时内工作。我不断收到错误。这里是我的代码:PHPMailer SMTP连接错误

<?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()功能的原因。

+0

你打算从localhost使用这些smtp吗? – Goikiu

+0

即使使用'SMTPDebug = 1',这就是*所有*信息? –

+0

您使用托管的网络服务器吗?也许防火墙阻止端口25.如果你可以通过SSH连接,请尝试'telnet你服务器smtp'并看看会发生什么。 – Jens

回答

1

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

$mail->host = $host; 

感谢@Rikesh提醒,$port也是同样的情况。

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

+1

“端口”一样。 – Rikesh

+0

嘿,谢谢你的答案,但我试过这个,它没有工作,同样的错误。试图从WAMP和网络服务器 – user3051223

+0

你尝试telnet到SMTP服务器? – Raptor

1

加入试试这个:

$mail->Mailer = "SMTP"; // SMTP Method 

请参考以下链接PHP Mailer help

+0

没有工作,对不起,同样的错误 – user3051223

+0

@Mukil OP已经说过'$ mail-> IsSMTP(); //通过SMTP发送。此外,您提供的链接不是官方文档。 – Raptor

0

尝试更改端口号

$port = 587; 

$port = 465; 

和检查什么新的错误哟你越来越,我相信你不会再次发生SMTP连接错误。

相关问题