SMTP PHP Mail Not Routed Through Dedicated IP Address

deltaend

Registered
Jan 30, 2007
4
0
151
So, I switched the option on in the WHM to send domain email out through dedicated IP addresses and it works great. The PHP based webmail clients built into cPanel work great and they send their emails from the correct IP address.

However, when using a LOCAL PHP based SMTP client and sending mail through, it always comes from the shared IP address of the server, NOT the dedicated one.

What I would love to know is... how do the native cPanel php based webmail apps route email through the system and how does that make them different than other PHP based authenticated clients?
 

sparek-3

Well-Known Member
Aug 10, 2002
2,019
225
368
cPanel Access Level
Root Administrator
I believe this functionality is dependent on the envelope-sender used to send the mail.

How are you sending mail in the PHP script?

If you are using the mail() function, then you need to specify a correct envelope-sender (sometimes called a return-path) using the fifth parameter of the mail() function.

http://us2.php.net/manual/en/function.mail.php

This would be something like

PHP:
mail("[email protected]","Subject","Message","Additional Headers","[email protected]");
Where [email protected] refers to a real e-mail address on the example.com domain that does exist. And example.com would need to have a dedicated IP with this exim functionality enabled.

If you are using an SMTP class for sending mail with PHP, then you need to specify a real e-mail address on the account as the envelope-sender when constructing the message. The envelope-sender address is what is specified in the MAIL FROM: command when constructing an SMTP message.
 

deltaend

Registered
Jan 30, 2007
4
0
151
I love you.

Yes, you hit the nail on the head in one. Now I am able to send out PHP based emails from the correct dedicated IP address as I should and apparently I can still spoof the emails as coming from a different source so people can just hit the reply button without worrying that they will return to the bounces email account if I format it correctly.

Below are settings for PHPmailer class:

$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "dedicatedipaddress"; // SMTP server


$mail->AddAddress("[email protected]");
$mail->SMTPAuth = true;
$mail->Username = "realusername";
$mail->Password = "realpassword";
$mail->From = "[email protected]";
$mail->FromName = "spoofedname";
$mail->Sender = "[email protected]";
$mail->SMTPDebug = true;
$mail->Port = 25;

$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}


I'm not sure if it works for other methods of emailing out, but I'm about to test. Thanks for the great intel!