Forum Moderators: coopster

Message Too Old, No Replies

PHP Mail not working where MX hosted by different server?

         

deejay

11:09 pm on Apr 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a website hosted on "SiteHost1", but the email is handled by "MailHost2" through an MX redirect.

General email is working fine and dandy.

The problem is that the PHP Mail script that I use to send emails to new users I have registered on the site is no longer working. In short emails are not arriving to the address they are sent to, but no errors are generated - the new member is being inserted into the database, and I am getting my on-screen confirmation that the email has been sent (see end of posted code), but it never arrives.

It worked fine prior to the MX redirect being put in place, and the identical code continues to work fine on another site I have where sitehost and mailhost are one and the same.

I am assuming therefore that it's likely something to do with the email being hosted remotely?

The following is the portion of my php code that sends the email, though as stated this has been working fine until now.

(get the info and insert in the database after error checking, etc, then send the following email:)

$userid = mysql_insert_id();
$subject = "Your membership at example.com";
$myname = "Mysite Webmaster";
$message = "<html>
<head>

</head>

<body>Dear $first_name $last_name, <p>

A user account has been created in your name at example.com.<p>

You are two steps away from logging in and accessing our exclusive members area.<p>

To activate your membership, please click <b><a href=\"http://www.example.com/be/activate.php?id=$userid&code=$db_password\">-here-</a></b>.<p>

Once you activate your membership, you will be able to log in with the following information:<p>

Username: $newusername<br>
Password: $random_password<p>

Thanks!<br>
Webmaster<p>

This is an automated response. Please do not reply </body></html>";

mail($email_address, $subject, $message,
"MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\nFrom: $myname<webmaster@example.com>n
X-Mailer: PHP/" . phpversion());

echo 'Membership information has been mailed to the new user\'s email address. User should check their email and follow the directions!<p><a href=adm_newuser.php>Register another new user</a>';

help?

[edited by: eelixduppy at 11:19 pm (utc) on April 30, 2007]
[edit reason] Please use reserved domain example.com [/edit]

deejay

2:29 am on May 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



doh! thanks eelix.

I have found the following comment to a similar situation posted on a cpanel forum (the site host uses cpanel):

"To get the emails to be delivered remotely you will need to have the domain name removed from /etc/localdomains and entered in /etc/remotedomains that way when exim goes looking for the mailbox to deliver to it will lookup the MX record for the domain externally and deliver it to their external mail server. Default is to deliver locally to all domains in /etc/localdomains
After you do that DO NOT click on the fix mailboxes link under the Email options in WHM or it will write it back into /etc/localdomains."

Now, I do have a folder named 'etc' above the root. there are no subfolders or files in there named localhost or remotehost though, so I'm loathe to do anything there without knowing what I'm doing.

In that etc folder I do have a file named .imapv4cp5c which appears to be empty and a folder named example.com.

In the example.com folder I have six files: 'password' 'password,v' 'quota' 'quota,v' 'shadow' and 'shadow,v'.

it's all greek to me, but I'm hoping it might spark a thought from someone else.

deejay

3:08 am on May 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



*SCREAMS*

Ok. Further progress.

Occurred to me that the new test members I had been trying to set up were using addresses at another of my sites, hosted on the same server as example.com.

So have tried setting up a member with a completely unrelated email address and the email has gone through fine.

Also tried setting up a member using an example.com email address, and this has also gone through fine.

It appears the problem is setting up members on other domains hosted on the same machine.

Any thoughts?

Anyone?

capulet_x

6:40 am on May 1, 2007 (gmt 0)

10+ Year Member



When you send something plain like this:

<?php
$to = "Joe@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>

Does your mail still not arrive?

deejay

12:09 am on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



good grief! Yep, capulet_x, that does work.. and now I know why.

mail($email_address, $subject, $message,
"MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\nFrom: $myname<webmaster@example.com>n
X-Mailer: PHP/" . phpversion());

See that little bold bit there? See how there's no backslash before the 'n'?

That's the answer. Just enough to send a malformed header and stuff it up.

I have, quite possibly, the greatest host in the world for going to the bother of sorting that out for me.

eelixduppy

12:12 am on May 2, 2007 (gmt 0)



hehe...your host really is nice. That was pretty hard to spot :)

It should be

\r\n
, though, not just
\n
.