告诉朋友表格不工作

时间:2011-04-24 08:53:51

标签: php forms mailer

<?php
  if ($_POST['friends-email']) {
      $name = "Sender's Name";
      $email = "sender@domain.com";
      $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>';
  }
?>

不确定为什么这不起作用,我收到“谢谢你的消息”,但是当我使用自己的电子邮件测试时,电子邮件没有发送。

3 个答案:

答案 0 :(得分:1)

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

然后,如果可行,请一次更换一个值,您将找到您的错误。我猜你是正则表达式替换。

答案 1 :(得分:1)

只是陈述显而易见的,但你把$email = "sender@domain.com";放在哪里,你实际上是将它改为变量吗?

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

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

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

$to      = 'dummymailing@mailinator.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n"; mail($to, $subject, $message, $headers);

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

如果您仍然遇到问题,可能与系统的sendmail功能有关。这篇关于serverfault的帖子提供了很多关于debugging the sendmail function的详细建议。

答案 2 :(得分:0)

尝试在if语句中附上邮件传递