phpemailphpmailerwhmexim

Set origin IP in PHPmailer


I wanted to rotate the origin IP addresses in an email script, it is used to send notifications to my customers.

My server comes with 5 ip addresses, so I created an array of IPs and while sending the IP address changed randomly, in this array I do not include the main server IP.

This was working fine until last december, I have not made any change nor update (I am not sure if there was any automatic)

Here is the script:

 $iparray = array(
    '163.xx.217.xx',
    '164.xx.217.xx',
);

$ips = $iparray;
$keyip = array_rand($ips);



        $mail = new PHPMailer();
        $mail->IsSMTP(); 
        $mail->CharSet = 'UTF-8';
        $mail->SMTPDebug  = 0;                     
        $mail->SMTPAuth   = true;                  
        $mail->SMTPSecure = "none";               
        $mail->Host       = $ips[$keyip];      
        $mail->Port       = 26;             
        $mail->AddAddress($recipient);
        $mail->Username=$senderemail;  
        $mail->Password=$senderpass;            
        $mail->SetFrom($senderemail,$sendername);
        $mail->AddReplyTo($senderemail,$sendername);
        $mail->AddBCC('smtp@xxxxx.co');
        $mail->Subject    = 'the subject';
        $mail->MsgHTML('the message);

Note that $mail->Host was an IP randomly selected from the array, when checking on the message received, I used to get this:

spf=pass (google.com: domain of test@xxxxxxx.co designates 163.xx.217.xx as permitted sender) smtp.mailfrom=test@xxxxxxx.co

However, since December, the SPF check is being made on the server main IP, instead of any of the selected IP in the array, which I do not want.

This was working properly but all of the sudden it changed, could it be Gmail servers? Could it be something to be configured in the server?

In order to send emails, I use Exim, installed on a Centos server, managed via WHM.

I am not trying to spoof any address, all IP addresses are mine, I just need to make sure they rotate on every email sent, and I could do it but now I am not sure what to change to make it work again.

Thanks for all your help


Solution

  • the solution was not directly in te PhpMailer, but as I am usin Exim as MTA, the answer is to set exim to read the IP from etc/mailips, and you can even map individual domains to any of your server IP address