Jump to content

Emails from PHP not arriving on some email addresses


Laurie_Hedge

Recommended Posts

Hi,

 

I'm new to these forums, so I hope I'm putting my question in the right place. Anyhow I've had a simple PHP email function that I've been using for a while, but I discovered today that it appears that emails sent using this function don't arrive when sent to @btinternet.com addresses. Gmail however receives them fine. I find this strange, as the mail function appears to return correctly, so it's definitely being sent. However the email is not being put into spam or even moved to trash, it simply doesn't arrive. I've also added the "Return-path" parameter to the header in the hopes of getting an error from the server, but I never receive anything back indicating that anything has gone wrong.

 

For testing, I've pulled my code out into its own page which contains only the following (except with real email addresses).

<?php
	function email($to, $subject, $message, $from)
	{
		$headers = "From: $from\r\nReturn-path: $from\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n";
		$message = wordwrap($message, 70);
		return mail($to, stripslashes($subject), stripslashes($message), $headers);
	}

	if (email("name@btinternet.com", "Testing...", "This is a test email...", "info@domain.com"))
		echo "Sent OK.";
	else
		echo "Send failed.";
?>

This code works fine when I send to a Gmail address, but when I send to a btinternet address (I've tried 2), as I described, it just never arrives.

 

I've been trying all kinds of things, like changing between "\r\n" and "\n" for the headers, changing the content type, adjusting the word wrap etc., but nothing helps the problem. I've also checked my website's IP to see if it's been blacklisted (I'm on shared web hosting), but it appears to be fine. For the record, my web host is 123-Reg. I was wondering whether anyone has encountered anything like this before, and if you have any suggestions for what else I might try?

 

Thanks in advance!

 

Laurie

Link to comment
Share on other sites

if this is a 'contact us' form and you always want to send to a specific email address, use one of the phpmail classes (phpmailer, switftmailer) and use smtp authentication against your receiving email account and send the emails directly to your remote email account. this will make your php script 'look' like an authenticated/logged-in email client connecting to your email account and eliminate the sending mail server at your web host from the process. you can also use this method to send emails through your remote email account, with whatever quantity restrictions your mail provider imposes.

 

if you do need to send through the mail server at your web hosting, i would start by finding out from them if your emails are actually being sent. just because the mail() function is returning a true value, doesn't mean that the mail server has sent or has any intention of sending the email. some mail servers are configured to return a true value/no errors regardless of what happens to the email so as to not allow hackers to use the returned errors to find mail box names...

 

next, the BT email server may be doing a more thorough check of the DNS records at your web hosting than what gmail is doing. the ONLY information a receiving mail server gets with any email is the ip address of the server/device the email is being sent from (from the tcp/ip data packets) and information in the email, i.e. the from address. the receiving mail server will use these two pieces of information to try and validate that the email is actually coming from where it says it is by checking the DNS records at the sending ip address and at the domain in the form address. perhaps the BT mail server is looking for a secondary piece of information that gmail isn't and something is either missing (missing values usually aren't a problem) or is set incorrectly (incorrect values will get an email discarded.)

 

to help resolve this, there is usually a 'postmaster' web page at the major email hosts that will tell you what is required to successfully send an email to their server. there is usually a contact email where you can either find if a sending mail server has been specifically blacklisted at that email host or to request that a sending mail server be white-listed. also, you can use the various tools at a site like dnsstuff.com to check for and check for errors in the DNS records for your domain and the mail server at your web host.

Link to comment
Share on other sites

Hi mac_gyver. Thanks for your help with this. Unfortunately it's not always being sent to the same email address, so I do think I need to send via my mail server. Given that the emails to the Gmail account are getting through, that surely means that the emails are being sent, right?

 

I must admit I'm not at all well versed in how the PHP mail() function actually works, but I started digging into it and I'm a little confused. I started by looking at the raw headers of the emails I did receive from the website in Gmail, and I noticed that the ip address is listed as 94.136.40.100, which when I ran it through a reverse-DNS search returned outbound-traffic.linweb.ahost.me, which is a) completely unfamiliar to me, and b) on at least one blacklist. So this certainly looks like a problem to me, because aside from being on a blacklist, it will also not match up with the address in the "from" field of the header. Is there any chance you could explain to me, or point me towards something that explains, what exactly is happening here? I would have expected the ip of my emails to be the same as the ip of the server on which the PHP script was running (i.e. my website's ip), but evidently I'm wrong. Why would this be? And is there anything I'm likely to be able to do about it given that I'm on a cheap shared web hosting package?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.