PHP 邮件无法运行

发布于 2024-11-18 06:10:26 字数 879 浏览 3 评论 0原文

我的 PHP 联系表单不会将我的电子邮件发送到任何地方,无论是收件箱还是垃圾邮件。 PHP 是最新版本,运行在安装了 SMTP 的服务器上。 我不确定这是我的代码还是软件...

这是我的 php 联系脚本:

    <?php
$to = "FILTERED";
$subject = $_POST['subject'];
$message = $_POST['message'] ." From: " .$_POST['email'];
$from =    "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>

和我的表单:

<form method='post' action='contactscript.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>

My PHP contact form does not send my email anywhere, be it Inbox or Spam.
The PHP is the latest edition and is running on a server which has SMTP installed on it.
I'm unsure whether it's my code or software...

Heres my php contact script:

    <?php
$to = "FILTERED";
$subject = $_POST['subject'];
$message = $_POST['message'] ." From: " .$_POST['email'];
$from =    "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>

and my form:

<form method='post' action='contactscript.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>

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

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

发布评论

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

评论(5

琉璃繁缕 2024-11-25 06:10:26

要确定问题是出在您的代码还是外部软件中,请检查 mail() 的返回值。

if ( mail($to,$subject,$message,$headers) ) {
    echo "Message was sent";
}
else {
    echo "Sending failed.";
}

如果它返回 false,则错误出在您的脚本中,或者您的邮件服务器不接受发送该邮件。

To determine whether the problem lies in your code or in the external software, check the return value of mail().

if ( mail($to,$subject,$message,$headers) ) {
    echo "Message was sent";
}
else {
    echo "Sending failed.";
}

If it returns false, the error lies in your script, or the message was not accepted for delivery by your mail server.

空‖城人不在 2024-11-25 06:10:26

我希望 - $to = "FILTERED";意味着您将过滤后的电子邮件地址放入 $to 中。如果 mail() 失败,您应该在 PHP 中收到错误消息。启用错误报告或检查日志文件。如果 mail() 没有失败,那么它不再是 PHP 问题,您应该检查邮件服务器。您还可以尝试使用带有硬编码值的 mail() 发送邮件,以查看邮件是否发出。

I hope - $to = "FILTERED"; means you are putting the filtered email addresses in $to. If mail() is failing, you should get an error in PHP. Enable error reporting or check the log file. If mail() is not failing then it's no more a PHP issue, you should check the mail server. You can also try to send a mail using mail() with hard-coded values to see if the mail goes out.

治碍 2024-11-25 06:10:26

也许在 From 冒号后面添加一个空格?

$headers = "From:" . $from; 

->

$headers = "From: " . $from;

但是,是的,无论是 var_dump 还是 echo out mail():

echo mail($blah,...);

1 表示成功,0 表示失败。

另外,$to 似乎不是有效的电子邮件地址。

Maybe add a space after the From colon?

$headers = "From:" . $from; 

->

$headers = "From: " . $from;

But yes, either var_dump, or echo out mail():

echo mail($blah,...);

1 is success, 0 would be failure.

Also, $to doesn't seem to be a valid email address..

凡尘雨 2024-11-25 06:10:26

我会使用 sendgrid 之类的东西外包它,每天免费发送 200 条消息。它确保您的邮件不会被标记为垃圾邮件,因为它使用 DKIM/SPF(您自己处理起来不太容易),而且您不必担心扩展。


I would outsource it using something like sendgrid with a free plan of 200 messages per day. It makes sure your messages don't get flagged as spam because it using DKIM/SPF(not that easy to handle yourself) plus you don't have to worry about scaling.


青春如此纠结 2024-11-25 06:10:26

尽管您可以使用 params 和配置变量更改此设置,但 php mail() 默认使用 sendmail。如果它没有安装在标准位置并且您没有显式配置它以使用其他方法,则 mail() 将失败。

Although you can change this with params and config variables, php mail() uses sendmail by default. If it is not installed in the standard location and you do not configure it explicitly to use another method, mail() will fail.

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