我有以下系统设置
- Windows XP 服务包 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);
关于php - 使用 PHP 通过 Gmail SMTP 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1881409/