为什么这个用于 HTML 表单的 PHP 邮件程序不能工作?

发布于 2024-12-03 19:15:46 字数 1760 浏览 0 评论 0原文

这是 PHP 代码:

<?PHP 
$to = "[email protected]"; 
$subject = "New Finance Request";
$headers = "Request:";
$forward = 0; 
$location = "";

$date = date ("l, F jS, Y"); 
$time = date ("h:i A"); 

$msg = "Below is the request sent on $date at $time.\n\n"; 

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    foreach ($_POST as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}
else {
    foreach ($_GET as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}

mail($to, $subject, $msg, $headers); 
if ($forward == 1) { 
    header ("Location:$location"); 
} 
else { 
    echo "Thanks!  Your request has been sent for approval and someone will be in contact with you soon!"; 
} 

?>

这是 HTML 代码:

<form action="mailer.php" method="post">
<strong>Name:</strong><br />
<input type="text"  name="Name" />
<br />
<br />
<strong>Email:</strong><br />
<input type="text" name="Email" />
<br />
<br />
<strong>Organization:</strong><br />
<input type="text" name="Org:" />
<br />
<br />
<strong>Amount:</strong><br />
<input type="text" name="Amount" />
<br />
<br />
<strong>Explain Request:</strong><br />
<textarea rows="5" cols="30" name="Message"></textarea>
<br />
<hr />
<input type="submit" name="submit" value="Submit">
</form>

我一辈子都无法让它真正发送电子邮件。它进入感谢页面,但我从未收到任何电子邮件...请告诉我,请在下面发表评论。

This is the PHP code:

<?PHP 
$to = "[email protected]"; 
$subject = "New Finance Request";
$headers = "Request:";
$forward = 0; 
$location = "";

$date = date ("l, F jS, Y"); 
$time = date ("h:i A"); 

$msg = "Below is the request sent on $date at $time.\n\n"; 

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    foreach ($_POST as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}
else {
    foreach ($_GET as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}

mail($to, $subject, $msg, $headers); 
if ($forward == 1) { 
    header ("Location:$location"); 
} 
else { 
    echo "Thanks!  Your request has been sent for approval and someone will be in contact with you soon!"; 
} 

?>

This is the HTML code:

<form action="mailer.php" method="post">
<strong>Name:</strong><br />
<input type="text"  name="Name" />
<br />
<br />
<strong>Email:</strong><br />
<input type="text" name="Email" />
<br />
<br />
<strong>Organization:</strong><br />
<input type="text" name="Org:" />
<br />
<br />
<strong>Amount:</strong><br />
<input type="text" name="Amount" />
<br />
<br />
<strong>Explain Request:</strong><br />
<textarea rows="5" cols="30" name="Message"></textarea>
<br />
<hr />
<input type="submit" name="submit" value="Submit">
</form>

I can not for the life of me get it to actually send the email. It goes to the thanks page, but I never receive any email...Let me know, comment below.

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

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

发布评论

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

评论(1

骄兵必败 2024-12-10 19:15:46

如果邮件确实发送或者有错误的话就这样写:

if (mail($to, $subject, $msg, $headers)){
  // email sent
}
else {
  echo 'some error occurred !';
}

Put it up like this if email is really sent or if there is an error:

if (mail($to, $subject, $msg, $headers)){
  // email sent
}
else {
  echo 'some error occurred !';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文