简单联系表格的问题

I apologize in advance for any rookie mistakes, as this is my first real attempt at piecing together a HTML / PhP contact form. I've scoured previous questions with identical issues and haven't found anything of substance.

The issue is the email is not sending. Things I've tried thus far: - Confirmed SMTP functions - Confirmed it's not a host-related issue - Used this exact form / PHP mailer on another template and it works fine - Checked spam folder

Here is the contact form itself:

    <form action="contact.php" method="POST" id="contact-form" class="form">
    <input type="hidden" value="" name="check">
    <noscript>
    <p class="noscript">JavaScript is required to use this form, please make sure your browser supports it.</p>
    </noscript>
    <p class="input">
    <label for="name" class="label">Name</label>
    <input type="text" name="name" id="name">
    </p>
    <p class="input">
    <label for="company" class="label">Company</label>
    <input type="text" name="company" id="company">
    </p>
    <p class="input">
    <label for="email" class="label">Email</label>
    <input type="text" name="email" id="email">
    </p>
    <p class="input">
    <label for="phone" class="label">Phone</label>
    <input type="text" name="phone" id="phone">
    </p>
    <p class="dark input">
    <label for="title" class="label">Project Title</label>
    <input type="text" name="title" id="title">
    </p>
    <p class="dark input">
    <label for="timeline" class="label">Timeline</label>
    <input type="text" name="timeline" id="timeline">
    </p>
    <p class="dark textarea">
    <label for="details" class="label">Details</label>
    <textarea name="details" id="details"></textarea>
    </p>
    <p>
    <label for="send" class="send-label">Everything look good? Click send.</label>
    <input type="submit" value="Submit" name="submit" class="button">
    </p>
    </form>

Here is the PHP mailer:

    <?php
    $field_name = $_POST['name'];
    $field_company = $_POST['company'];
    $field_email = $_POST['email'];
    $field_phone = $_POST['phone'];
    $field_title = $_POST['title'];
    $field_timeline = $_POST['timeline'];
    $field_message = $_POST['details'];

    $mail_to = 'MyEmail@email.com';
    $subject = 'Quote request from '.$field_name;

    $body_message = 'From: '.$field_name."
";
    $body_message .= 'E-mail: '.$field_email."
";
    $body_message .= 'Message: '.$field_message;

    $headers = 'From: '.$field_email."
";
    $headers .= 'Reply-To: '.$field_email."
";

    $mail_status = mail($mail_to, $subject, $body_message, $headers);

    if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
    alert('Thank you for the message. We will contact you shortly.');
    window.location = 'contact.html';
    </script>
    <?php
    }
    else { ?>
    <script language="javascript" type="text/javascript">
    alert('Message failed. Please contact the webmaster.');
    window.location = 'contact.html';
    </script>
    <?php
    }
    ?>

Just for reference, the "MyEmail@email.com" is not the email I use. I used a substitute for privacy purposes.

Thank you!

Sending mail from PHP is fraught with difficulties. You might not have an error in your code, but the mail might not be delivered because (select as many as you wish):

  • it doesn't appear to come from an email address on the server;
  • outbound email is blocked by default until you ask for it;
  • Outbound mail on port 25 is blocked, and you have to use a specific server.
  • your server is blacklisted;
  • your message is blocked by a spam filter;
  • some other reason.

Make life easy on yourself. Use a library like swiftmailer or PHPmailer to handle sending the mail, and try something easy like delivering to an address on the sending server. Then work up from there. Be prepared to have to use SMTP Authentication, and possibly a paid external service to send the mail for you.

$field_message is blank. Where is it on the form and then in the mail processing script?