0

I maybe out of date on this, so feel free to tell me so! Just gone back to an old form, replicated it for a standard site, no back end database or CMS system.

Form looks like this:

<form action="contact-form-handler.php" method="post">
    <div>
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" />
    </div>
    <div>
        <label for="email">E-mail:</label>
        <input type="email" name="email" id="mail" />
    </div>
        <div>
        <label for="number">Telephone:</label>
        <input type="number" name="number" id="number" />
    </div>
    <div>
        <label for="message">Message:</label>
        <textarea id="message" name="message" id="message"></textarea>
    </div>
    <div class="button">
        <button type="submit">Send your enquiry</button>
    </div>
</form>

The PHP looks like this:

<?php $errors = '';$myemail = '**removed**';//<-----Put Your email address here.
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$number = $_POST['number']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^",$email_address))

{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Quotation form submission: $name";
    $email_body = "You have received a new message from your website".
    "Here are the details:
    \n Name: $name 
    \n Telephone Number: $number
    \n Email: $email_address
    \n More Info: \n $message"; 

    $headers = "From: $myemail"; 

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: thank-you.html');
} 
?>

Now when I've uploaded, it looks like it works, but nothing gets emailed. Obviously there is a correct email address in the PHP at the top, I've just removed it for the innocence sake!

Any ideas? Am I too out of date for this to do what it used to? It's currently here: http://www.fatherof4.co.uk/rb/contact.html

Thanks in advance :)

Spike_C
  • 1
  • 1
  • The mail() method uses sendmail, is the servers php.ini have the required sendmail configuration? Also, anything in the php_error.log file? – Brian Bolli Mar 24 '16 at 00:42
  • Check your spam, your code works fine. `if(mail($to,$email_subject,$email_body,$headers){ header('Location: thank-you.html'); } else { echo "Something went wrong."; }` – Funk Forty Niner Mar 24 '16 at 00:43
  • Definitely nothing in spam.. I'll check with hosts on requirement thank you. This was marked as duplicate but after going through the forums I couldn't solve it... – Spike_C Mar 25 '16 at 07:12

0 Answers0