Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SMTP PHP Mail Not Routed Through Dedicated IP Address

Discussion in 'E-mail Discussion' started by deltaend, Oct 31, 2008.

  1. deltaend

    deltaend Registered

    Jan 30, 2007
    Likes Received:
    Trophy Points:
    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?
  2. sparek-3

    sparek-3 Well-Known Member

    Aug 10, 2002
    Likes Received:
    Trophy Points:
    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.

    This would be something like

    mail("[email protected]","Subject","Message","Additional Headers","[email protected]");
    Where [email protected] refers to a real e-mail address on the domain that does exist. And 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.
  3. deltaend

    deltaend Registered

    Jan 30, 2007
    Likes Received:
    Trophy Points:
    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!

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice