繁体   English   中英

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

[英]Sending email through Gmail SMTP using PHP

我有以下系统设置

  • 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); 

通过Google发送的邮件需要通过SSL运行。

主题上有很多arcticles,你可能会觉得这很有用: http//deepakssn.blogspot.com/2006/06/gmail-php-send-email-using-php-with.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM