1

So when I execute this without modifying the header information to send html type emails it sends however when I have it send with it being an html email it never gets sent.

here is the code:

<?php
    $to = "[email protected]";
    $subject = "Order Confimation - mywebsite.com";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= "From: <[email protected]>";
    $message = "
        <!DOCTYPE html>
        <html lang='en-us'>
            <head>
                <meta charset='utf-8'>
                <title>Order Confirmation</title>
                <style type='text/css'>
                    //style information
                </style>
            </head>
            <body>
                <div class='box'>
                    <h1 class='right'>Thanks!</h1>
                    //Blah blah blah
                </div>
            </body>
        </html>
    ";

    mail($to, $subject, $message, $headers);

    if (mail($to, $subject, $message, $headers)) {
        echo "<p class='hide'>E-mail Sent</p>";
    } else {
        echo "<p class='hide'>Problem</p>";
    }           
?>

And it returns E-mail sent however the email never goes to the inbox

Any suggestions?

Also pear package is enabled.

3
  • 1
    My guess is it's probably being caught by your spam filter. Your if (mail()) part should be fine. And just double check the email address you're sending to. Commented May 25, 2012 at 17:25
  • @jimD Yeah I double checked spam folder but nothing there either. Commented May 25, 2012 at 17:30
  • Yeah that was what I had originally however I changed it due to suggestion on the forms changed it back, still not getting the email through Commented May 25, 2012 at 17:56

4 Answers 4

2

There's nothing wrong with your code as written above (with the exception that you call mail() twice - once outside the error check loop, once inside the 'if' - so you send 2 emails)

A quick test delivered fine to a Google Apps email address, so there's nothing about the code that specifically should be causing problems.

Spam filtering is a cumulative game. There can be multiple small things wrong none of which mark you as spam, but cumulatively tip your score over the limit.

In this case, you're sending a solely HTML email without a text/plain component. This is a negative mark against your score which seems to be acting as the straw to break the camel's back. If you're sending from a shared host with poor reputation you may get a few more points against you, and your PHP mail settings may be pushing an invalid return-path or other origin-based error which also count against.

You could try sending a multipart with both text/plain and text/html per http://krijnhoetmer.nl/stuff/php/html-plain-text-mail/

If that doesn't work, then if you post the full headers of the successful plaintext email then I might be able to see if you have other indicators.

Gmail will accept most mail, but just blackhole it after acceptance, so if you're using that to test you won't get much feedback.

Email's a tricky game, and if you're needing to get delivered for your app's success, you may want to consider using a third party service:

These services are designed around sending event-driven email from apps and handling all the mess on the ISP delivery end.

Full Disclosure: I am the Deliverability guy at PostageApp

Sign up to request clarification or add additional context in comments.

Comments

0

I noticed you don't have

$headers .= 'To: ';

Could that have something to do with it?

Comments

0

I think you need to include the SMTP settings for outgoing mail if you are using mail function in php. So technically your mail will be reported as sent but would not have gone through the mail provider. (I know you need to do that in java when using the mail function.)

2 Comments

Wouldn't I have to do the same without the text/html if that was the case, because when I send it without the html editing it sends.
do you mean if you have html in your php file, it does not go through ? try having your html code in a different file.
0

mail function returns true, so you should say :

// mail() function return 0 if all right, so compare this with 0
if (mail($to, $subject, $message, $headers)) {
    echo "E-mail Sent";
} else {
    echo "Problem";
}  

Not :

if (mail($to, $subject, $message, $headers)==0)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.