How to change default mail sender (alias/via) when using Zend_Mail? i.e. remove "via" in gmail

StackOverflow https://stackoverflow.com/questions/15213915

  •  18-03-2022
  •  | 
  •  

Question

When I send email using Zend Mail using the following code:

    $to = array("email1@gmail.com","email2@hotmail.com","email3@yahoo.com");        
    $msg = file_get_contents("email.html");             
    $mail = new Zend_Mail ( "UTF-8" );
    $mail->setMessageId ( "MyMsg__" . md5 ( microtime () ) );
    $mail->addHeader ( "Content-Type", "text/html; charset=UTF-8" );
    $mail->setBodyHtml ( $msg  );
    $mail->setSubject ( "News Letter Test" );       
    $mail->setReplyTo('newsletter@mydomain.com', 'Some Name');
    $mail->addHeader('MIME-Version', '1.0');
    $mail->addHeader('Content-Transfer-Encoding', '8bit');
    $mail->addHeader('X-Mailer:', 'PHP/'.phpversion());
    $mail->setFrom ('newsletter@mydomain.com', 'Some Name');
    foreach($to as $ml){
        $mail->addTo ( $ml );       
    }
    $mail->send ( $transport );

I get this in gmail:

newsletter@mydomain.com via u4552323.onlinehome-server.com

How do I remove this part: via u4552323.onlinehome-server.com

Notice I have full root access and this is a dedicated server, if the problem is in send_mail config, or hosts, how do I change this part u4552323.onlinehome-server.com ?

Was it helpful?

Solution

Google displays the 'via' information in Gmail in when messages are sent through another domain. In your case, the message is coming from an address in the mydomain.com domain, but the mail server is in the onlinehome-server.com domain.

You can avoid this by sending mail through the SMTP server for the mydomain.com domain (assuming your hosting provider doesn't block such traffic). If can control the DNS and mail server configuration for the onlinehome-server.com server, you can also configure SPF and DKIM, as explained in Google's documentation (but this may not be an option depending on your hosting environment).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top