微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我有以下系统设置

> 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

有什么建议?

解决方法:

我一直使用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); 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐