Web Design Forums

Coding Articles & Tutorials

Read about HTML, PHP, Java, and many other popular languages.

Using PHP mail() Headers to Pass Spam Filters



Site of the Month Voting - Now Open. CAST YOUR VOTE NOW!

Reply
 
LinkBack Thread Tools
Old July 24 '06, 01:34 PM (#1)
smoseley is online now
WDF Moderator
 
smoseley's Avatar
 
Join Date: March 2003
Location: Miami, FL
Posts: 8,719
smoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud of
Using PHP mail() Headers to Pass Spam Filters

Using PHP mail() Headers to Pass Spam Filters

by Steven Moseley

Ok, so you've set up a nice mail form on your remotely hosted PHP site, but every time you send an email to someone through it, it seems to get derailed by spam filters??? There's a simple reason for this.

Why Your Message Is Seen as Spam
Spam filters check the actual routing of the message to see what domain it originated from, and match that up against the email address in the "From" header to see if they match. If you're on a shared-server hosting environment, the originating domain will not be yours, and the message will therefore fail.

Here's a typical use of the PHP mail() function to send an email:
PHP Code:
<?
    mail
("recipient@recipient-domain.com""Test Message""This is my message to you."
        
"From: Some One <someone@mydomain.com>");
?>
Here's what the headers look like :
Code:
Return-path: <mydomain@host104php5sql5.myhost.com>
Envelope-to: recipient@recipient-domain.com
Delivery-date: Mon, 24 Jul 2006 12:06:10 -0500
Received: from mydomain by host104php5sql5.myhost.com with local (Exim 4.52)
     id 1G53sf-0008HX-TP
     for recipient@recipient-domain.com; Mon, 24 Jul 2006 12:06:09 -0500
To: recipient@recipient-domain.com
Subject: Test Message
From: Some One <someone@mydomain.com>
Message-Id: <E1G53sf-0008HX-TP@host104php5sql5.myhost.com>
Date: Mon, 24 Jul 2006 12:06:09 -0500
Notice that the originating domain (in the "Received" header) is myhost.com. That is my web host. Using the PHP mail() function will use my default mail account with the host (in this case, "mydomain" at "myhost.com" to send the message. Because the originating domain ("myhost.com") and the "From" header domain ("mydomain.com") do not match, spam filters will raise a flag and derail the message.

Well, don't bang your head against the wall just yet. There's a work-around for it.

How to Correct the Problem

There are a few possible solutions to the problem. Most of them involve changing server settings or PHP's mail() settings so that your domain can be reflected in the "Received" header. These are not a possibility in a shared hosting environment, so I'm not going to bother with those.

The simple solution to get past spam filters, though it's not the prettiest alternative. Basically, you want to change the "From:" header to "mydomain@myhost.com" (the actual account sending the email), but add a "Reply-To:" header for "someone@mydomain.com". The PHP code will look like this:
PHP Code:
<?
    $header 
.= "Reply-To: Some One <someone@mydomain.com>\r\n";
    
$header .= "Return-Path: Some One <someone@mydomain.com>\r\n";
    
$header .= "From: Some One <mydomain@myhost.com>\r\n";
    
$header .= "Organization: My Organization\r\n";
    
$header .= "Content-Type: text/plain\r\n";

    
mail("recipient@recipient-domain.com""Test Message""This is my message to you."$header);
?>
And the full headers will look like this:
Code:
Return-path: <mydomain@host104php5sql5.myhost.com>
Envelope-to: recipient@recipient-domain.com
Delivery-date: Mon, 24 Jul 2006 12:25:23 -0500
Received: from mydomain by host104php5sql5.myhost.com with local (Exim 4.52)
     id 1G54BH-0000uE-1h
     for recipient@recipient-domain.com; Mon, 24 Jul 2006 12:25:23 -0500
To: recipient@recipient-domain.com
Subject: Test Message
Reply-To: Some One <someone@mydomain.com>
From: Some One <mydomain@myhost.com>
Organization: My Organization
Content-Type: text/plain
Message-Id: <E1G54BH-0000uE-1h@host104php5sql5.myhost.com>
Date: Mon, 24 Jul 2006 12:25:23 -0500
Now, the only problem is that when I receive the message, I see the "From" field:

Code:
From: Some One <mydomain@myhost.com>
However, when I reply to the email, it replies to "Some One <someone@mydomain.com>" - which is good.

There is another option, which is a little prettier, which is to set your "From:" field to "someone@mydomain.myhost.com". This will make your message a little less confusing to the people you're sending it to. The from field will then look like this:

Code:
From: Some One <someone@mydomain.myhost.com>
This is what I'm doing to bypass spam filters.

Good luck, and don't spam people!

- Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 29 '06, 12:33 PM (#2)
hagen is offline
WDF Regular
 
hagen's Avatar
 
Join Date: August 2005
Posts: 316
hagen will become famous soon enough
Hi Steve, thanks for sharing, thats just what I need for my new "bulk email" tool...

Cheers -Hagen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 6 '07, 06:19 AM (#3)
montyauto is offline
New Member!
 
montyauto's Avatar
 
Join Date: December 2006
Posts: 1
montyauto is an unknown quantity at this point
Good stuff,
thanks for sharing,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Web Design Help » Articles & Tutorials » Coding Articles & Tutorials

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 19 June 18 '10 02:20 PM
php mail() to junk mail Petachok PHP 0 February 12 '05 08:54 PM
php in flash - mail form mortal wombat PHP 3 January 21 '05 04:12 AM
How to use XML to pass data from ASP/MSSQL to PHP? Wired HTML and CSS Help 5 January 2 '05 12:39 AM

 
User Infomation
Your Avatar

Site Of The Month
Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:05 PM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164