0

I've got the website hosted and I've created the form and the PHP but I can't get the form to actually send the e-mail. I'm quite sure I set out all of the variables correctly. The form does actually submit, after the user submits something the alert pops up fine and the form isn't shown but I never receive the email. Here is my code:

<?php
if (isset($_REQUEST['email']) && isset($_REQUEST['fullname'])) {

//Email information
$admin_email = 'myemail.hotmail.co.uk';
$fullname = $_REQUEST['fullname'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$followup = $_REQUEST['followup'];
$comment = $_REQUEST['comment'];

//send email
mail($admin_email, $fullname, $comment, 'From: ' . $email . 'Phone: ' . $phone . 'Follow up? ' . $followup);

//Email response
$contactThanks = "Thank you for contacting us!";
echo "<script type='text/javascript'>alert('$contactThanks');</script>";
}

//if 'email' variable is not filled out, display the form
else {
?>

<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
    <table class='contactForm'>
        <tr>
            <td><label for='fullname'>*Full Name:</label></td>
            <td><input type='text' name='fullname' id='fullname' /></td>
        </tr>
        <tr>
            <td><label for='email'>*Email:</label></td>
            <td><input type='text' name='email' id='email' /></td>
        </tr>
        <tr>
            <td><label for='phone'>Phone:</label></td>
            <td><input type='tel' name='phone' id='phone' /></td>
        </tr>
        <tr>
            <td><label for='followup'>Follow Up:</label></td>
            <td><input type='text' name='followup' id='followup' /></td>
        </tr>
        <tr>
            <td><label for='comments'>Comments:</label></td>
            <td><textarea type='text' name='comments' id='comments'></textarea></td>
        </tr>
        <tr>
            <td id='inputButtons' colspan='2'>
                <input type='submit' value='Submit' id='submit'/>
                <input type='reset' value='Reset' id='reset'/>
            </td>
        </tr>
    </table>
</form>
<?php
}
?>

can anybody see why this isn't working? Thanks.

  • provide information on input you are sending.. admin email is with wrong format $admin_email = 'myemail.hotmail.co.uk'; – vineet verma Oct 17 '14 at 08:45
  • yeah sorry that was a botch job where I removed my actual email with a substitute one for the post, in my code its in the right format. – Dave Kennedy Oct 17 '14 at 09:03

1 Answers1

0

Assign the mail function's return value to a variable and check if the mail is actually sent or not. For example:

$sent = mail($admin_email, $fullname, $comment, 'From: ' . $email . 'Phone: ' . $phone . 'Follow up? ' . $followup);

if ($sent) {
    // thanks, mail sent
} else {
    // error, mail failed to send
}

I suspect you don't have a mail server (e.g. sendmail) installed on your server.

Latheesan
  • 23,247
  • 32
  • 107
  • 201
  • Update: Just got it working, the code for the mail() is the same, I had to play with some settings, but the issue now is that its putting all of the information from the mail() into the "From" part of the email. – Dave Kennedy Oct 17 '14 at 09:00