2010-10-21 176 views
0

我写了一些代码使用PHPMailer从我的PHP脚本发送电子邮件。出于某种原因,脚本不发送消息。发送电子邮件从PHP脚本


这里是我的代码:

<?php 
require_once("PHPMailer/class.phpmailer.php"); 
$mail=new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPAuth = true; 
$mail->Host = "ssl://smtp.gmail.com"; 
$mail->Port = 465; 
$mail->Username = "[email protected]"; 
$mail->Password = "PASSHERE"; 
$mail->SetFrom = "[email protected]"; 
$mail->AddAddress("[email protected]"); 
$mail->Subject = "Confirm Web Lock Registration!"; 
$mail->Body = "Please confirm your Web Lock Registration by clicking here!"; 
$mail->WordWrap = 50; 

if(!$mail->Send()) 
{ 
    echo 'Message was not sent.'; 
    echo 'Mailer error: ' . $mail->ErrorInfo; 
} else { 
    echo "Message Sent!"; 
} 
?> 

此相呼应的错误:

SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host. 
+0

你是否得到了你的错误消息,如果有的话,它是什么? – 2010-10-21 17:19:43

+0

你能提供更多关于这个问题的信息吗?它打印出错误信息,还是说“发送消息!”但你仍然没有收到它? – erjiang 2010-10-21 17:20:14

+0

@Zachary Brown:绝不会像这样公开分享您的用户名和密码:) – Sarfraz 2010-10-21 17:21:23

回答

2

我也使用PHPMailer,只是尝试了你的设置,并得到了同样的错误。 这里是我为我设置女巫的工作(我与展示 - >>巫东西你没有,或者是不同的我)

$mail->PHPMailer = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPAuth = true; 
->> $mail->SMTPSecure = "ssl"; 
->> $mail->Host = "smtp.gmail.com"; //not ssl://smtp.gmail.com 
$mail->Port = 465; etc... 

其他的都是一样的,只不过我不使用单词换行,但我检查,它不会导致问题。

1

你需要指定的Gmail用户名和密码,因为这是你在smtp设置中使用什么:

$mail->Username = "[email protected]"; 
$mail->Password = "yourgmailpassword"; 
+0

地址是用户名。该公司使用Google Apps进行电子邮件。 – 2010-10-21 17:36:34

3

您的错误消息可能是由服务器上的防火墙设置引起的。此错误消息通常是由阻止端口上的传出连接的防火墙引起的。

您还应该确保您已启用openssl扩展。

你固定的原始答:

要发送到[email protected]这是不是你想要的地址。

您需要删除第二个.com和更改为[email protected]

+0

更正了它。仍然是同样的问题。 – 2010-10-21 17:38:30

+0

我根据您提供的错误消息添加了一些其他问题。 – 2010-10-21 17:55:17

1

作为一般的提示,尝试开启调试:

$mail->SMTPDebug = 2; // enables SMTP debug information (for testing) 
         // 1 = errors and messages 
         // 2 = messages only 

从SO:Debugging PHP Mail() and/or PHPMailer

0

正如有点建议你可能也想尝试使用Zend_Mail,你可以愉快地使用它,而不必去完整的MVC路线,它是非常丰富的信息