php 无法发送邮件

发布于 2024-12-16 19:19:00 字数 1111 浏览 0 评论 0 原文

php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = "ssl://smtp.gmail.com"
; http://php.net/smtp-port
smtp_port = 465  

我想使用 gmail SMTP 服务器 在 php 中发送电子邮件,并在 php.ini 上进行了更改(参见上面的代码)。还要将 $host、$port、$username 和 $pw 添加到 sendEmail.php 中。

但是,电子邮件仍然无法发送出去。谁能帮助我吗?谢谢!

sendEmail.php

 $host = "ssl://smtp.gmail.com";
 $port = "465";
 $username = "[email protected]";
 $password = "password";

 $email_to = "[email protected]";
 $email_subject = "Test E-Mail";
 $email_body = "Email Body";

 if(mail($email_to, $email_subject, $email_body)){
    echo "The email was successfully sent.";
 } else {
    echo "The email was NOT sent.";
 }

?>

php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = "ssl://smtp.gmail.com"
; http://php.net/smtp-port
smtp_port = 465  

I would like to send email in php using gmail SMTP server and did change on php.ini(See above code). Also add $host, $port, $username and $pw into the sendEmail.php.

However, email still can not be sent out. Can anyone help me? Thanks!

sendEmail.php

 $host = "ssl://smtp.gmail.com";
 $port = "465";
 $username = "[email protected]";
 $password = "password";

 $email_to = "[email protected]";
 $email_subject = "Test E-Mail";
 $email_body = "Email Body";

 if(mail($email_to, $email_subject, $email_body)){
    echo "The email was successfully sent.";
 } else {
    echo "The email was NOT sent.";
 }

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2024-12-23 19:19:00

如果您使用像 PHPMailer 这样的库来实现此目的,事情很可能会变得容易得多:

http://phpmailer.worxware。 com/

使用此类将有助于设置正确的标头、配置寻址并确保总体上更好的可交付性。

这是一个连接到 gmail SMTP 的示例,就像您所描述的那样:

http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/

Things will very likely be much easier for you if you use a library like PHPMailer for this purpose:

http://phpmailer.worxware.com/

Using this class will aid in setting proper headers, configuring addressing and ensuring better deliverability in general.

Here's an example connecting to the gmail SMTP just like you described:

http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文