drelgkxl93433 2012-06-24 15:54
浏览 60
已采纳

本机php邮件功能似乎不适用于Gmail

I am trying to use the native PHP function to send a simple test email through gmail SMTP, but it's not working. Going through various forums including Stack Overflow and the only solutions I see are the ones that recommend third-party email libraries/frameworks/api's. Does this mean that PHP's mail() does not work with Gmail, and if so, why?

The following is the code:

<?php
$to ="mail2@yahoo.com";
$sbj ="test mail";
$msg ="testing! testing!! testing!!!";

ini_set("SMTP", "ssl://smtp.gmail.com");
ini_set("smtp_port", 465);
ini_set("sendmail_from", "mail1@gmail.com");

$header ="From: " .ini_get("sendmail_from");

mail($to, $sbj, $msg, $header);

?>

And the error message I got:

Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\test\web1\test1.php on line 12

  • 写回答

3条回答 默认 最新

  • douxiajia6104 2012-06-24 16:07
    关注

    Does this mean that PHP's mail() does not work with Gmail, and if so, why?

    Gmail servers require user to authenticate before sending any message, mail() does not provide any authentication method

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?