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

标签 php

我有以下系统设置

  • 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/

相关文章:

php - 使用 codeigniter PayPal_Lib 库的 PayPal 定期付款

php - 无需等待 CURL 请求完成即可流式传输响应

php - Mysql数据将在表列中显示 "Array"

php - 将 JSON 解析数组转换为 CSV

php - 在 PHP 中,NULL 和将字符串设置为等于 2 个单引号之间有什么区别

php - 警告 : imagedestroy(): 7 is not a valid Image resource

php - 将 cookie 从浏览器传递到 Guzzle 6 客户端

php - 表单需要将数据发布到 codeigniter 中的 Controller

php - 当我尝试使用 Hex2bin 将编码数据转换为二进制时,Hex2bin 不起作用

php - 当用户向下滚动时加载元素