告诉朋友表格不起作用
<?php
if ($_POST['friends-email']) {
$name = "Sender's Name";
$email = "[email protected]";
$recipient = preg_replace("/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是说明显而易见的事情,但是您将
$email = "[email protected] 的位置]";
,您实际上是将其更改为变量,对吗?您是否已打开并显示所有 PHP 错误?
使用 PHP 交互模式 (
php -a
) 部署电子邮件然后前往此处检查是否已收到。这只是为了检查您的电子邮件客户端是否有问题 - 即它没有阻止电子邮件。
如果您仍然遇到问题,则可能与系统的 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?
Use PHP interactive mode (
php -a
)to deploy an emailThen 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.
您是否尝试过使用硬编码值的邮件功能来检查 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.
尝试将邮件传递包含在 if 语句中
Try enclosing the mail delivery in an if statement