PHP脚本不从HTML表单发送电子邮件

时间:2018-01-05 03:42:01

标签: php html email

我在下面的HTML文件中创建了表单,并在下面创建了PHP文件。但是我似乎无法将其发送到列为“$ to”的电子邮件地址。

我不断收到“未发送电子邮件”的消息,这是在电子邮件发送时应该返回的内容...但我不知道为什么。

<form method="POST" action="mailer.php" id="formid">
 <div class="row">
    <div class="col-md-6">
        <div class="form-group">
            <input type="text" class="form-control" name="name" placeholder="Your Name" required="">
        </div>
    </div>

    <div class="col-md-6">
        <div class="form-group">
            <input type="email" class="form-control" name="email" placeholder="Email" required="">
        </div>
    </div>
 </div>



  <div class="form-group">
    <textarea class="form-control" name="message" rows="8" placeholder="Message"></textarea>
  </div>

  <div class="center-content">
    <input type="submit" value="SEND" class="btn btn-lg">
  </div>

<?php
if(isset($_POST['submit'])) 
{
    $to = "myemail@email.com";
    $subject = "Customer Enquiry";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];

    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

    echo "Thanks for your enquiry! Expect a response within 24 hours.";
    mail($to, $subject, $body);
} 
else 
{
    echo "Email not sent";
}
?>

0 个答案:

没有答案