告诉朋友表格不起作用

发布于 2024-11-03 08:51:59 字数 1085 浏览 7 评论 0原文

<?php
  if ($_POST['friends-email']) {
      $name = "Sender's Name";
      $email = "[email protected]";
      $recipient = preg_replace("/[^a-z0-9 !?:;,.\/_\-=+@#$&amp;\*\(\)]/im", "", $_POST['friends-email']);
      $recipient = preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient);
      $mail_body = "Default Description";
      $subject = "Default Subject";
      $header = "From: " . $name . " <" . $email . ">\r\n";
      mail($recipient, $subject, $mail_body, $header);

      echo 'Thank you for recommending <br /> us!';

  }  else {
      echo '<form action="" method="post" name="send2friend" id="send2friend">
                Friends Email*:
                <input name="friends-email" id="friends-email" type="text" />
                <input type="submit" value="continue" />
            </form>';
  }
?>

不知道为什么这不起作用,我收到“谢谢消息”,但当我使用自己的电子邮件进行测试时,电子邮件未送达。

<?php
  if ($_POST['friends-email']) {
      $name = "Sender's Name";
      $email = "[email protected]";
      $recipient = preg_replace("/[^a-z0-9 !?:;,.\/_\-=+@#
amp;amp;\*\(\)]/im", "", $_POST['friends-email']);
      $recipient = preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient);
      $mail_body = "Default Description";
      $subject = "Default Subject";
      $header = "From: " . $name . " <" . $email . ">\r\n";
      mail($recipient, $subject, $mail_body, $header);

      echo 'Thank you for recommending <br /> us!';

  }  else {
      echo '<form action="" method="post" name="send2friend" id="send2friend">
                Friends Email*:
                <input name="friends-email" id="friends-email" type="text" />
                <input type="submit" value="continue" />
            </form>';
  }
?>

Not sure why this isn't working, I get the "thank you message" but the email is not delivered when I test using my own emails.

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

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

发布评论

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

评论(3

心舞飞扬 2024-11-10 08:51:59

只是说明显而易见的事情,但是您将 $email = "[email protected] 的位置]";,您实际上是将其更改为变量,对吗?

您是否已打开并显示所有 PHP 错误?

error_reporting(E_ALL);
ini_set('display_errors', '1');

使用 PHP 交互模式 (php -a) 部署电子邮件

$to      = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n"; mail($to, $subject, $message, $headers);

然后前往此处检查是否已收到。这只是为了检查您的电子邮件客户端是否有问题 - 即它没有阻止电子邮件。

如果您仍然遇到问题,则可能与系统的 sendmail 功能有关。这篇关于 serverfault 的文章提供了许多关于调试 sendmail 功能

Just stating the obvious, but where you have put $email = "[email protected]";, you are actually changing that to a variable right?

Do you have all PHP errors turned on and displaying?

error_reporting(E_ALL);
ini_set('display_errors', '1');

Use PHP interactive mode (php -a)to deploy an email

$to      = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n"; mail($to, $subject, $message, $headers);

Then go here to check that it's received. This is just to check that it's not a problem with your email client - i.e. it's not blocking the email.

If you're still having problems, it could be something to do with the system's sendmail function. This post on serverfault provides a lot of detailed advice on debugging the sendmail function.

错爱 2024-11-10 08:51:59

您是否尝试过使用硬编码值的邮件功能来检查 phpmail 是否设置正确?

然后,如果可行,一次替换每个值,您就会发现错误。我猜这是你的正则表达式替换。

Have you tried the mail function with hardcoded values, to check phpmail is set up right?

Then if that works, replace each value one at a time, and you will find your bug. I am guessing it is you regular expression replace however.

岁月静好 2024-11-10 08:51:59

尝试将邮件传递包含在 if 语句中

Try enclosing the mail delivery in an if statement

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