简体   繁体   English

未从 PHP mail() 方法接收电子邮件

[英]Not receiving email from the PHP mail() method

I have tried to set-up an email.html and an action.php so that someone can send an email from a website.我试图设置一个 email.html 和一个 action.php,以便有人可以从网站发送电子邮件。 Here is the code in email.html这是 email.html 中的代码

<form action="./action.php" method="post">
    <p>Your Name</p>
    <p><input type="text" name="name" /></p>
    <p>Email</p>
    <p><input type="text" name="email" /></p>
    <p>Services</p>
    <p><input type="text" name="service" /></p>
    <p>Requests</p>
    <p><textarea rows="8" cols="32" name="comment"></textarea></p>
    <p><input type="submit" value="Send" /></p>
</form>

In action.php I have在 action.php 我有

<?php
    $to = "foo@outlook.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "foo2@gmail.com";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
?>

The information entered in email.html successfully load into action.php, but nothing is received in my Outlook inbox from the email method.在 email.html 中输入的信息成功加载到 action.php 中,但我的 Outlook 收件箱中没有从电子邮件方法收到任何信息。 Am I missing something?我错过了什么吗?

Start by checking the return value of mail to see if the message is being accepted by your SMTP server.首先检查mail的返回值,看看邮件是否被您的 SMTP 服务器接受。

Also, per Namecheap's documentation, your From address is invalid .此外,根据 Namecheap 的文档, 您的发件人地址无效

Only domains that are hosted on our servers can be used in 'From' field.只有托管在我们服务器上的域才能用于“发件人”字段。 Any domain that is not hosted with us cannot be added to 'From' field.任何不是由我们托管的域都不能添加到“发件人”字段。 We had to take this measure to prevent sending spam using forums, guest books and contact forms scripts.我们必须采取这一措施来防止使用论坛、留言簿和联系表单脚本发送垃圾邮件。 For your site scripts to work properly you should set 'From' field to email account that has been created in your cPanel.为了使您的站点脚本正常工作,您应该将“发件人”字段设置为已在您的 cPanel 中创建的电子邮件帐户。

Even if this were allowed by your hosting company, you shouldn't be sending mail from @gmail.com using non-Gmail servers anyway.即使您的托管公司允许这样做,您也不应该使用非 Gmail 服务器从 @gmail.com 发送邮件。 It will often be blocked by SPF and other such anti-spam measures on the receiving end.它通常会接收端的 SPF和其他此类反垃圾邮件措施阻止

First check result of the mail.首先检查邮件的结果。 You also should check the php error log file.您还应该检查 php 错误日志文件。

when your mail is really going out, use an valid sender email, then you can get bounces from the receiving mail server.当你的邮件真的出去时,使用有效的发件人电子邮件,然后你可以从接收邮件服务器收到退回邮件。

don't forget, there are many anti spam technology's.不要忘记,有许多反垃圾邮件技术。 most important is that you respect and know how SPF is working.最重要的是您尊重并了解SPF的工作原理。 that's one of the most fails, websites doesn't send emails which don't arrive at recipient.这是最失败的问题之一,网站不会发送未到达收件人的电子邮件。

Well, banged my head hard.. Just to realise they were going in Spam folder of my "$to" email id.好吧,狠狠地敲了敲我的头......只是意识到他们进入了我的“$to”电子邮件ID的垃圾邮件文件夹。 Also check this on your side.也请检查这一点。

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

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