PHP电子邮件表单未在提交时发送电子邮件

时间:2020-01-13 01:59:07

标签: php html forms email

当我在自己的网站上提交表格时,它没有给我任何错误,但是我没有收到电子邮件。我的代码在下面。

PHP处理程序:

<?php

ini_set( display_errors, 1 );

error_reporting( E_ALL );

$_SESSION['previous'] = 'http://'. $_SERVER[HTTP_HOST]. $_SERVER[REQUEST_URI];

$name = $_POST['name'];
$visitor_email = $_POST['uid-email'];
$message = $_POST['message'];
$address = $_POST['autocomplete_search'];

$email_from = "request@cubedpotato.com";

$email_subject = "Repair Request";

$email_body = "\n Name: $name\n".
"Email: $visitor_email\n".
"Address: $address\n".
"Message: $message\n";

$to = "MY_EMAIL@test.com"; //usually has my personal email in it, removed for security purposes

$headers = "From: $email_from \r\n";

$headers .= "Reply-To: $visitor_email \r\n";

$repair_type  = 'None';
if(isset($_POST['repair_type']) && is_array($_POST['repair_type']) && count($_POST['repair_type']) > 0){
  $repair_type = implode(', ', $_POST['repair_type']);
}

$email_body .= "Repair Types: " . $repair_type;


if (mail($to,$email_subject,$email_body,$headers) == true) {
  if(isset($_REQUEST["destination"])){
    header("Location: {$_REQUEST["destination"]}");
  }else if(isset($_SERVER["HTTP_REFERER"])){
    header("Location: {$_SERVER["HTTP_REFERER"]}");
  }else{
    header('Location: ../index.php');
  }
} else {
  echo "Error with sending Form!";
}
?>

HTML表单:

<form class="contact-form" action="../test.php" method="post">
  <input type="hidden" name="destination" value="<?php echo $_SERVER["REQUEST_URI"]; ?>"/>
  <div class="repair_opt">
    <label class="container"> HDD Repair - $99.99
      <input type="checkbox" name="repair_type[]" value="XboxOneS_hdd_repair" data-id="0">
      <span class="checkmark"></span>
    </label><br></br>
    <i class="more-info-icon" name="hdd_modal"></i>
  </div>
  <div class="repair_opt">
    <label class="container"> HDMI Repair - $99.99
      <input type="checkbox" name="repair_type[]" value="XboxOneS_hdmi_repair" data-id="1">
      <span class="checkmark"></span>
    </label><br></br>
    <i class="more-info-icon" name="hdmi_modal"></i>
  </div>
  <div class="repair_opt">
    <label class="container"> Overheating Repair - $99.99
      <input type="checkbox" name="repair_type[]" value="XboxOneS_overheat_repair" data-id="2">
      <span class="checkmark"></span>
    </label><br></br>
    <i class="more-info-icon" name="overheat_modal"></i>
  </div>
  <p id="total">Total: $0.00</p>
  <input type="text" name="name" maxlength="50" placeholder="Your Name" required>
  <input type="email" name="uid-email" maxlength="50" placeholder="Your Email Address" required>
  <input id="autocomplete_search" name="autocomplete_search" type="text" class="form-control" placeholder="Address (Street Address, State, Zip Code)" />
        <input type="hidden" name="lat">
        <input type="hidden" name="long">
  <textarea id="message" name="message" maxlength="1000" cols="25" rows="6" placeholder="Message..." required></textarea><br>
  <button type="submit" name="submit-form">Submit</button>
</form>

我已经与我的主机进行了核对,由于我之前遇到问题,因此没有垃圾邮件过滤器处于活动状态,我的表单已按之前的方式工作,然后在我更新它时随机停止了工作。我将其还原了,但仍然无法正常工作。我和主持人坐在一起的技术支持聊天室,尝试对它进行故障排除,但没有任何运气。任何帮助将不胜感激。

0 个答案:

没有答案