View Full Version : PHP mail being delivered to wrong address

10-12-2009, 06:10 PM
Hi guys,

I have a script to send emails that works perfectly from my local testing server.

When I uploaded it to the server the site is hosted on the emails are then not delivered correctly.

Im developing the system from my company where we all have an email address under the same domain ie: im 'me@testcompany.com' and the boss is 'boss@testcompany.com'.

When I use the script to send myself an email it ends up in the bosses inbox and not mine!!

Script works perfectly fine if im sending an email to my hotmail address.

Its odd because the exact same email generated from my local testing server (using ISP's SMTP) correctly delivers the email to my address, and not the bosses!!

Any ideas where I should start hunting for issues?


10-12-2009, 08:11 PM
haven't had much experience using SMTP from localhost but you'll probably need to provide some code in order to get any advice

does this problem only occur with this mail script?

10-13-2009, 10:31 AM
Heres the code

Works perfectly well to other email address, just when its going to my work address gets routed to the boss instead


//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

$body = file_get_contents('mailtest.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "localhost"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only

$mail->SetFrom('me@testcompany.co.uk', 'me');

$mail->AddReplyTo('me@testcompany.co.uk', 'me');

$mail->Subject = "MailTest SMTP";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test


$address = "me@testcompany.co.uk"";
$mail->AddAddress($address, "me");

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";


10-13-2009, 10:53 AM
$address = "me@testcompany.co.uk"";

You have a typo at this line. There should be only 1 double quote at the end. Is this a typo in your post only or you have a typo like this in the real script too ?

Edit: I guess it is in the post only since you said it worked ... Have you deployed exactly the same script locally and at the server ?

Just in case: Could it be that you have different $address when you test the script locally and at the server ? At some hosts the incoming mail could be configured to deliver all e-mails with not existing in the system e-mail address to some particular e-mail (like mail@testcompany.co.uk). I would check the e-mail address $address for typos very carefully while testing ...