简体   繁体   English

PHP邮件功能未发送

[英]PHP mail function not sending

For some reason, my PHP mail is not sending. 由于某些原因,我的PHP邮件未发送。

This is my script: 这是我的脚本:

$tom = $email;
$subjm = 'Company: Forgotten password';
$msgm = "-- DO NOT REPLY TO THIS EMAIL --\nHi,\nYou have forgotten your password.\nHereby we want to supply a you a new one.\nNew password: $pass";
$msgm = wordwrap($msgm, 70);
$mail_sent = @mail($tom, $subjm, $msgm);
echo "$tom <br /> $subjm <br /> $msgm";
echo $mail_sent ? "Mail sent" : "Mail failed";
echo "<br />Your new password has been sent to the email you've signed up with.<br />If you can't find the email, please wait a few minutes or check your spam box.";

However, it always gives me "Mail failed", and I do not see it in mailbox. 但是,它总是给我“邮件失败”,并且在邮箱中看不到它。 I've checked if the correct emailadress was being produced by my script ( $email ), and it was. 我检查了我的脚本( $email )是否生成了正确的emailadress,并且确实如此。 So I'm kinda lost as to why it will not send. 所以我有点迷茫,为什么它不发送。

You need to supply a from address in order to conform to RFC. 您需要提供from地址才能符合RFC。 Also the return value of mail does not tell you if the mail was sent or not. mail的返回值也不会告诉您邮件是否已发送。 It does only tell you if the underlying mail server accepted the mail. 它只会告诉您基础邮件服务器是否接受了邮件。

For a more elegant way to send mail not only using your local sendmail but by any SMTP server have a look at phpmailer . 为了更优雅地发送邮件,不仅可以使用本地sendmail,而且可以通过任何SMTP服务器发送邮件,请查看phpmailer

As a follow up to the comments, I contacted my webhost. 作为评论的后续,我联系了我的虚拟主机。 They tell me I can't send emails using the mail function to recipients that are not on the domain. 他们告诉我,我无法使用邮件功能向不在域中的收件人发送电子邮件。 I'm resolving the issue with them. 我正在与他们解决问题。

Edit: 编辑:

I needed to add a From:, and the emailadress of From should be a @mydomain.com address, not external. 我需要添加一个发件人:,发件人的emailadress应该是@ mydomain.com地址,而不是外部地址。 It works now. 现在可以使用了。

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

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