使用PHP通过Gmail SMTP发送电子邮件

4

我有以下系统设置

  • Windows XP Service Pack 2
  • WAMP 2.0
  • PHP 5.3

我已经配置了我的php.ini文件如下:

smtp=smtp.gmail.com
smtp_port=25;

我的PHP代码是

<?php
    mail('alagar.pandi@gmail.com','test subject','test body');
?>

我收到的错误信息是:
Warning: mail() [function.mail]: SMTP server response: 
530 5.7.0 Must issue a STARTTLS command first. 
4sm389277yxd.16 in C:\wamp\www\limosbusesjets\test.php on line 5

有什么建议吗?
2个回答

4

我一直使用PHPMailer来满足我的所有邮件需求。 它内置支持GMail作为服务器(而且是免费的)。

我认为你的问题在于你试图使用PHP的邮件设置而不是PHPMailer的。 确保你已经设置了以下内容:

$mail               = new PHPMailer();  //Setup the mailer
$mail->IsSMTP();
//$mail->SMTPDebug      = 2;
$mail->SMTPAuth     = true;                     //enable SMTP authentication
$mail->SMTPSecure   = "ssl";                    //sets the prefix to the servier
$mail->Host         = "smtp.gmail.com";         //sets GMAIL as the SMTP server
$mail->Port         = 465;                      //set the SMTP port
$mail->Username     = $guser;       //GMAIL username
$mail->Password     = $gpwd;                //GMAIL password
$mail->AddReplyTo($fromAddress,$fromName);
$mail->From         = $guser;
$mail->FromName     = "Your name";  
$mail->Subject      = $subject;     //E-Mail subject
$mail->AltBody      = $bodyAlt;         //Text Body
$mail->WordWrap     = 50;              //set word wrap
$mail->Priority = $priority;          //Mail priority
$mail->MsgHTML($ebody); 

我曾经使用过它,但是它显示以下错误 SMTP错误:无法验证身份 - Mayan Alagar Pandi
看看我的修改...在Gmail上使用SMTP不是25端口,而是465。请查看PHPMailer目录中的docs/use_gmail.txt。 - Jason
谢谢,那帮了我很多!应该是那个问题的被采纳答案! - Chris

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接