PHP邮件处理程序通过两次电子邮

Sea*_*ean -3 php email

我有一个带有邮件处理程序的表单,它发送一个表单作为电子邮件TWICE .....我感觉它是由于这行代码将用户重定向到错误或成功页面,如果邮件发送或不.(我不使用Mailto)

以下是我认为导致问题的代码行:

mail($recipient, $subject, $formcontent, $mailheader);

if(mail($recipient, $subject, $formcontent, $mailheader)){
  header("Location: success.html");
} else {
  header("Location: error-enquiry.html");
}
Run Code Online (Sandbox Code Playgroud)

这是我的完整php:

<?php 
$name = $_POST['name'];
$references = $_POST['references'];
$information = $_POST['information'];
$checkbox = $_POST['checkbox'];
$email = $_POST['email'];
$formcontent="From: $name \n references: $references \n information: $information \n checkbox: $checkbox";
$recipient = "@None of your business";
$subject = "Enquiry Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader);

if(mail($recipient, $subject, $formcontent, $mailheader)){
  header("Location: success.html");
} else {
  header("Location: error-enquiry.html");
}

if (isset($_POST['checkbox'])) {
  $checkbox = "yes";
} else {
  $checkbox = "no";
}

exit; 
?>
Run Code Online (Sandbox Code Playgroud)

我不知道我在这方面做错了什么......有人可以帮我吗?

干杯,肖恩

Peo*_*eon 5

mail($recipient, $subject, $formcontent, $mailheader); /// <-- Remove this

if(mail($recipient, $subject, $formcontent, $mailheader)){
   ...
Run Code Online (Sandbox Code Playgroud)

您正在发送邮件,然后再次发送邮件以检查结果

删除第一个邮件条目