Question

Possible Duplicate:
Mail not being received by hotmail.com

I have this simple form on my site and I do not receive emails when it sends into my Hotmail account, not even the Junk folder.

Here is the form code:

<form action="mail.php" method="POST">
    <p><label title="Name">Name:</label><br />
        <input type="text" name="name" autocomplete="on" required="required"></p>
    <p><label title="Email">Email:</label><br />
        <input type="text" name="email" autocomplete="on" required="required"></p>
    <p><label title="About">My message is about...</label><br />
        <select name="about">
            <option value="general">General Query</option>
            <option value="wedding">Wedding</option>
            <option value="corporate">Corporate Event or Trade Show</option>
            <option value="other">Other Event</option>
        </select>
    <p><label title="Message">Message:</label><br />
        <textarea name="message" rows="6" cols="25" required="required"></textarea></p>
    <input type="submit" value="Send">
</form>

And the mail.php file:

<?php 
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $about = $_POST['about'];
        $formcontent="From: $name \n About: $about \n Message: $message";
        $recipient = "MyEmailAddress@Live.co.uk";
        $subject = "Contact Form";
        $mailheader = "Reply-To: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Thank You!";
?>

I do end up seeing a page with "Thank you!" displayed but no email is received.

Was it helpful?

Solution

Mail delivery is a tricky business... just because you send mail does not mean that anyone will receive it. Many receiving servers will simply ignore the incoming message if it does not meet certain criteria (in my experience Gmail and Hotmail are particularly prone to just silently denying delivery, so it doesn't even end up in SPAM). There are a few things to make sure you've done:

1) You've set up PTR/SPF (reverse lookup) entries in your DNS records

2) Make sure that you're not on any blacklists (http://www.mxtoolbox.com/blacklists.aspx)

3) Expand your headers

$headers = "MIME-Version: 1.0\r\n"
          ."Content-Type: $contentType; charset=utf-8\r\n"
          ."Content-Transfer-Encoding: 8bit\r\n"
          ."From: =?UTF-8?B?". base64_encode("Your sending display name") ."?= <$from>\r\n"
          ."Reply-To: $replyTo\r\n"
          ."X-Mailer: PHP/". phpversion();

However, if you really want to ensure that mail gets through, send mail via SMTP. You can never guarantee mail delivery, but it will be much more reliable. If you're not sending a large volume of mail, you might try using Mandrill or similar service to relay emails for you.

OTHER TIPS

You can use the following method. returns true on success.

function sendMail($email, $subject, $message)
{
    $supportEmail = 'info@abc.com';
    $from = 'Abc';
    $msg  = $message;
    $from = str_replace(' ', '-', $from);
    $frm  = $from.' <'.$supportEmail.'>';
    preg_match("<(.*)@(.*\..*)>", $frm, $match);

    ///////////////////Headers/////////////////
    $hdr='';
    $hdr.='MIME-Version: 1.0'."\n";
    $hdr.='content-type: text/html; charset=iso-8859-1'."\n";
    $hdr.="From: {$frm}\n";
    $hdr.="Reply-To: {$frm}\n";
    $hdr.="Message-ID: <".time()."@{$match[2]}>\n";
    $hdr.='X-Mailer: PHP v'.phpversion();
    $x=@mail($email, $subject, $msg, $hdr);
    if($x==0)
    {
        $email=str_replace('@','\@', $email);
        $hdr=str_replace('@','\@',$hdr);
        $x=@mail($email, $subject, $msg, $hdr);
    }
    return $x;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top