PHP mail() 函数服务器和本地主机不工作 [英] PHP mail() function server and localhost not working
问题描述
我正在尝试在我的一个网页上发送一封简单的电子邮件.
I am trying to send a simple email on one of my web pages.
mail('myemail@gmail.com', 'NEW ORDER', '订单详情');
该代码在我的 xampp localhost 和我的服务器上都不起作用.(我没有收到电子邮件).我读到必须在我的服务器上编辑 php.ini 文件,但它似乎允许(基于我的微不足道的知识).
The code does not work on my xampp localhost, nor my server. (i received no emails). I read about having to edit a php.ini file on my server, but it seemed to allow it (based on my minuscule knowledge).
【邮件功能】sendmail_path =/usr/local/bin/sendmail -oi -t
我的主要目标是能够在我的实际网站上发送它.(我不担心实际的本地主机)
My main goal is to be able to send it on my actual website. (im not as worried about the actual localhost)
推荐答案
您需要确保电子邮件发件人"地址是您服务器上存在的有效地址 - 请参阅我的回答等
You need to ensure that the email "From" address is a valid address which exists on your server - see my answers among others
并且您的 mail();
上需要一个发件人" - 您似乎缺少它 - 请参阅
And you need a "From" on your mail();
- which you appear to be missing - see
添加回复:"标题并使用您从用户那里获得的电子邮件地址,以便您收到一封可以回复的电子邮件,而不是默认发送到您的服务器.
Add a "Reply-To:" header and use the email address which you get from your user in that, so that you receive an email which you can reply to rather than it defaulting to going to your server.
其他有用的评论:PHP 邮件由于某种原因无法正常工作
我个人最喜欢的解决方案也被很多人推荐:PHPMailer https://github.com/PHPMailer/PHPMailer
My personal favourite solution also recommended by plenty of others: PHPMailer https://github.com/PHPMailer/PHPMailer
这篇关于PHP mail() 函数服务器和本地主机不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!