OM2 Posted July 14, 2011 Share Posted July 14, 2011 I have an email script It's consistently without failure ALWAYS sending the email to the Spam folder (Despite having a million times marked it as not spam) I was hoping someone could have a look and tell me what the problem is (+ Comments on other mistakes would be great! I put the scrip together by scraping bits of code samples I found) + I'd add that other service providers seem to be OK and receive the email - it's just Google that doesn't like it : ( + The server is fine and not on a blacklist - I've checked The script is: <?php $TO = "orders@dummy.com, dummy.shop@gmail.com"; $FROM = "orders@dummy.com"; $BCC = "dummy@dummy2.com"; $mobileEmail = "dummy@dummy2.com"; $mobileEmailFrom = "websiteorders.dummy@dummy.com"; $customerEmailSubject = "Thank you for your order at dummy"; $shopEmail = "dummyWebOrders@dummy.com"; if($HTTP_POST_VARS['firstName_dta']!="") { $firstName_dta = $HTTP_POST_VARS['firstName_dta']; $lastName_dta = $HTTP_POST_VARS['lastName_dta']; $address_dta = $HTTP_POST_VARS['address_dta']; $postcode_dta = $HTTP_POST_VARS['postcode_dta']; $telephone_dta = $HTTP_POST_VARS['telephone_dta']; $mobile_dta = $HTTP_POST_VARS['mobile_dta']; $email_dta = $HTTP_POST_VARS['email_dta']; $orderReviewText_dta = $HTTP_POST_VARS['orderReviewText_dta']; $additionalInstructions_dta = $HTTP_POST_VARS['additionalInstructions_dta']; // Start of email sent to shop $subject = "Order from " . $firstName_dta; $bodyString = "First Name: " .$firstName_dta . "\n"; $bodyString = "Last Name: " .$lastName_dta . "\n"; $bodyString .= "Address: " .$address_dta . "\n"; $bodyString .= "Post Code: " .$postcode_dta . "\n"; $bodyString .= "Telephone: " .$telephone_dta . "\n"; $bodyString .= "Mobile: " .$mobile_dta . "\n"; $bodyString .= "Email: " .$email_dta . "\n"; $bodyString .= "Order: \n\n" . $orderReviewText_dta . "\n"; if($additionalInstructions_dta != "") { $bodyString .= "(" . $additionalInstructions_dta . ")"; } $header = 'From: '.$FROM . "\r\n" . "Bcc: " . $BCC. "\r\n" . 'X-Mailer: PHP/' . phpversion(); $ok=mail($TO,$subject,$bodyString,$header); echo "result=$ok"; // End of email sent to shop PC // Start of email sent to customer $customerBodyString = "Thanks you for your order at dummy.\n\n"; $customerBodyString .= "Your order details received by us were:\n\n"; $customerBodyString .= "------------------------------------\n\n"; $customerBodyString .= $bodyString; $customerBodyString .= "\n\n------------------------------------\n\n"; $customerBodyString .= "We'll have your order with you shortly.\n\n\n\n"; $customerBodyString .= "dummy"; $header = 'From: '.$shopEmail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $ok=mail($email_dta,$customerEmailSubject,$customerBodyString,$header); // End of email sent to customer // Start of email sent to mobile $mobileSubject = ""; $mobileBodyString = $firstName_dta . "\n"; $mobileBodyString .= $address_dta . "\n"; $mobileBodyString .= $postcode_dta . "\n"; $mobileBodyString .= $telephone_dta . "\n"; $mobileBodyString .= $mobile_dta . "\n"; if(preg_match('/^[a-zA-Z0-9_\-\+\. ]+$/', $orderReviewText_dta)) { // The input has only the allowed characters // So, we don't need to do any replacing } else { // The input has some non-allowed characters in it // So, we do need to do some replacing $orderReviewText_dta = preg_replace('/[^a-zA-Z0-9_\-\+\.\: ]/', '', $orderReviewText_dta); while (preg_match('/::', $orderReviewText_dta)) { $mobileOrderReviewText_dta = str_replace('/::', ':', $orderReviewText_dta); } while (stristr($orderReviewText_dta, "::")) { $orderReviewText_dta = str_replace("::", ":", $orderReviewText_dta); } $orderReviewText_dta = str_replace(":", "\n", $orderReviewText_dta); } $mobileBodyString .= $orderReviewText_dta; $header = 'From: '.$mobileEmailFrom . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $ok=mail($mobileEmail,$mobileSubject,$mobileBodyString,$header); // End of email sent to mobile } else { echo "result=0"; } ?> THANKS in advance OM Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 14, 2011 Share Posted July 14, 2011 There are a multitude of reasons why an email may find its way into the spam folder. It can be difficult to impossible to actually determine the cause. Here are some things to consider. What email server are you using to send the email? If it is a gmail address and you are not sending the email through gmail's servers it could be targeted as spam. Sort of like receiving a letter where the return address is yours but you know you didn't send it to yourself. Is the email server that is sending the email the "approved" server for the domain used as the from address? Similar to the above. Some email servers - when receiving email - will check the domain of the from email address and then do a reverse-lookup on the originating server to see if it is the authoritative email server for the domain. This prevents spammers from sending email trying to impersonate an official email address: e.g. support@yourbank.com There are lots of additional headers you can set in the email that can help prevent email from being identified as spam. I'm not real familiar with them off hand, but you could do some googling on the subject. Quote Link to comment Share on other sites More sharing options...
OM2 Posted July 14, 2011 Author Share Posted July 14, 2011 thanks for the reply. i thought that there might be a problem with my script the email address is a google applications one how do i sent using gmail servers? i know how to do when setting up an account on outlook - but not sure how to do using a php script i didn't say the whole story actually before: everything was fine recently (a week or so): i had my server moved to another server - this is when problems all started (my hosting company has checked and has confirmed everything is ok and working as it should be) i'm at a loss as i said: it's ONLY just gmail that has the problem Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 14, 2011 Share Posted July 14, 2011 That makes sense. You are sending an email with a "From" address that has a domain that Google is supposed to be administrating. But, that email is being sent from an email server (I'm guessing some email server maintained by your hosting company) that is not maintained by google. Basically, when the email hits the google email server it sees the from address and realizes that it did not send the email and it is supposed to be the one that should. If you look at the other spam email in there you will see that there are email messages "from" yourself. But, you obviously didn't send them - they are sent from any number of servers with a from address posing as you. Here is a possible solution to allow you to send the mail using google's servers rather than your hosts server. http://www.cyberciti.biz/tips/howto-php-send-email-via-smtp-authentication.html Quote Link to comment Share on other sites More sharing options...
OM2 Posted July 15, 2011 Author Share Posted July 15, 2011 thanks for the reply this script has been working for years i get moved to a new server and it stops working i've now tried sending from another hostiing company i host with on another domain (sending emails from the other domain) everything works fine - emails come in a split second - and DON'T get stuck in the spam folder seems like the problem is to do with the new server - but the hosting company say they have checked absolutely everything and done everything - and that there's nothing wrong whatsoever don't know what to do Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 15, 2011 Share Posted July 15, 2011 seems like the problem is to do with the new server - but the hosting company say they have checked absolutely everything and done everything - and that there's nothing wrong whatsoever They are correct. They cannot control what happens to an email after it is sent. The email is sent, so their email server has done it's job. After that, there is nothing they can do to affect whether an email ends up in the spam folder or not. Many spam detectors will blacklist certain SMTP server. And, the company hosting the server may not even be aware. If a software company that produces spam detecting software find that there are a large number of spam emails coming from a particular server they may update their program to automatically flag any emails from that server as spam. Or, that process may be automatic for all I know. So, it could be that a client (or multiple clients) of your hosting company were using their hosting accounts to send out spam which caused their server to be blacklisted. There is nothing you can do about it. And, the only thing your hosting company could do is contact the company that is blacklisting their server and plead their case. That assumes that they really are blacklisted and they know which company is blacklisting them. As a test, try sending an email using a different from address and see if that get's caught in spam or not with gmail. It won't solve the problem, but it will at least tell you if the problem is due to the from email address. The bottom line is that it is difficult, if not impossible, to determine why an email gets caught in spam. If it were easy to make sure email did not end up in spam then all the spammers would do that and the spam detection would be worthless. Quote Link to comment Share on other sites More sharing options...
OM2 Posted July 15, 2011 Author Share Posted July 15, 2011 thanks for the reply my email subject shouldn't be gmail - that was incorrect it seems that others are affected SAME problem with yahoo with regards to recipients - there are only about 2 or 3 email addresses it sends email to!! and 2 of them are my addresses!! it's got to do with the hosting server Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 15, 2011 Share Posted July 15, 2011 it's got to do with the hosting server No it does not, and I doubt that it is since the emails are apparently being received to some addresses. I must not be making myself clear, so I will try again with more detail When an email is received by an email server it *may* check the domain of the FROM address in the email and then do a validation of the email server that sent the email. If that server is not the authoritative server to send emails for that domain, the incoming server may not even accept the email or let it though only to be targeted as spam. To avoid this you can either use the correct email server for the domain you are using in the from email address or you can see about adding an appropriate SPF record into the DNS settings for your domain. I, personally, have not done that, but I have gone through all of this with my company when we had numerous "email issues" with our product. Quote Link to comment Share on other sites More sharing options...
OM2 Posted July 15, 2011 Author Share Posted July 15, 2011 thanks for taking the time to write the replies - really appreciated i've read all ur replies, but things still just don't add up for me - current server - problems - email not being received by google and yahoo + others i would assume (is being received by bt.com email addresses) - old server which hosted the domain 7 days ago - everything fine both the above cases, the script is sending mail from the SAME domain that are sending - i have taken the script to another hosting company - that doesn't host the domain - it can send emails fine - the emails are from the original domain that it does not host this is the bit i don't get and think its something to do with the new server: the moment the move is made, the email problems start Quote Link to comment Share on other sites More sharing options...
xyph Posted July 15, 2011 Share Posted July 15, 2011 If the EXACT same script works on one host, and not the other, it could be the hosting server's fault. Whether is has to do with the server being blacklisted, or the server sending bad responses, or having incorrect sendmail settings, etc, I have no idea. Some can be fixed, some can't. The server IS sending the mail, but it may be making no attempts to assure the recipient that the mail is legit. I wouldn't say it's broken, but I'd say it isn't working correctly. Quote Link to comment Share on other sites More sharing options...
OM2 Posted July 15, 2011 Author Share Posted July 15, 2011 If the EXACT same script works on one host, and not the other, it could be the hosting server's fault. Whether is has to do with the server being blacklisted, or the server sending bad responses, or having incorrect sendmail settings, etc, I have no idea. Some can be fixed, some can't. The server IS sending the mail, but it may be making no attempts to assure the recipient that the mail is legit. I wouldn't say it's broken, but I'd say it isn't working correctly. THANK YOU! i'm not an email expert i'm not a server expert but some of the fact of my case clearly point to JUST one thing Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.