Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a simple template that I have been using to send emails to my website users using php.

I have noticed now that for some strange reason gmail seems to think that my emails are spam and as a result every mail from my website that gets sent to a gmail address ends up in the spam folder.

As the domain is a new domain i doubt that the reason for this is due to my site being flagged as one that distributes spam in some way, so i have concluded that it must be down to my user of the html and possibly the way that I have used hyperlinks.

If someone could look through the brief example I have put below and explain to me what i am doing wrong in all of this, it would be greatly appreciated as i have been scratching my head for a long time now and this seems to be valid and according to the specification?

Any input, suggestions, feedback or thoughts would be welcome, thank you!

<?php
// multiple recipients
$to  = "exampleuser@gmail.com";

// subject
$subject = 'Please Confirm User Account Registration';

// message
$message = '
<html>
<head>
    <title>My Domain User Account Registration</title>
</head>
<body>
    <p>My Domain User Account Registration :</p>
    <p>We have just received a request to have your information added to our website as a user account. This would enable you to buy products on our website at <a href="http://www.mydomain.com/">http://www.mydomain.com/</a></p>
    <p>If this is correct and you do wish to create a new user account on our website, please click the link below to be directed our website.</p>
    <p><a href="http://www.mydomain.com/users/register/confirmation/confirm.php?confirm=12345&key=12345abcde">http://www.mydomain.com/users/register/confirmation/confirm.php?confirm='.$userId.'&key='.$randomKey.'</a></p>
    <p>If you received this email by mistake, simply delete it. You won&rsquo;t be subscribed if you don&rsquo;t click the confirmation link above and your email address will be removed from our database by tomorrow.</p>
    <p>For questions about this message, please contact us at : <a href="mailto: info@mydomain.com">info@mydomain.com</a></p>
    <p>Thank you.</p>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: Accounts @ www.mydomain.com <accounts@mydomain.com>' . "\r\n";

//Send the message
mail($to, $subject, $message, $headers);
?>
share|improve this question

2 Answers 2

If you can, take out this:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

You are then sending the emails as plain text and they won't be automatically detected as spam.

share|improve this answer
up vote 0 down vote accepted

After badgering my host for quite some time about the subject it turns out that their server has been basically marked as a sender of spam, so mails from my website that was on the shared server in question were automatically being sent to the spam folder for gmail users...

Something to be aware of!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com?utm_source=stackoverflow.com&amp;utm_medium=site-ui&amp;utm_campaign=footerlink\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>                   with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.12.19.2131\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </no"], "copyright__copyright__copyright": [" for quite some time about the subject it turns out that their server has been basically marked as a sender of spam, so mails from my website that was on the shared server in question were automatically being sent to the spam folder for gmail users...\n\nSomething to be aware of!\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}