How to remove “via” and server name when sending mails with PHP?

前端 未结 5 1983
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 03:54

When I send a mail with PHP the destinatary gets a header like this one:

   noreply@justwalk.it **via** de p3nlhg147.shr.prod.phx3.secureserver.net


        
相关标签:
5条回答
  • 2020-11-29 04:39

    I also fetched the same problem. But I have overcome the problem by using the following code:

    mail('maaaa@abcd.com', 'the subject', 'the message', null,'-faaa@abc.com');
    

    Make sure that last parameter is -f with the email address.

    You can add the

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";<br />
    mail('maaaa@abc.com', 'the subject', 'the message body in html format', $headers,'-faaaa@abc.com');
    

    for the html message body in email.

    0 讨论(0)
  • 2020-11-29 04:45

    Yes, you can get rid the "via" part. Here's the details:

    1) SPF and DKIM
    

    Firstly, you would need to set an SPF record for the domain you are sending emails from and enable DKIM as well. These are primarily for identifying your messages against spam.

    2) "From: anything@yourdomain.com"
    

    Secondly, make sure you are setting the “From: ” header to be an email address on the domain you are sending messages from. Don’t pretend to be someone else. Use “From: someone@abc.com” if you are sending the messages from abc.com, rather than anything else, such as blah@def.com, or yours@gmail.com, or whatever. If you want the recipient to reply to your Gmail email instead of your domain email, use the “Reply-To: ” header. “From: ” must always be the domain email that you are sending the email from.

    3) "Return-Path: return@yourdomain.com"
    

    Thirdly and most importantly, set the “Return-Path: ” header to be the same domain as that of the “From: ” header. Use the 5th parameter of the mail() function for this:

    mail('recipient@example.com', 'Subject', "Message Body", $headers, '-freturn@yourdomain.com')
    

    So the Return-Path of this message would be “return@yourdomain.com” (the email address immediately following the -f switch). The $headers parameter should contain all the necessary message headers. Make sure “From: ” is something@yourdomain.com.

    After these steps and measures, Gmail should now completely trust your messages from yourdomain.com. The ‘via‘ field of your messages should be gone and the ‘mailed-by‘ field as well as the ‘signed-by‘ field should be correctly showing up as yourdomain.com.

    Hope it helps!

    0 讨论(0)
  • 2020-11-29 04:48

    This is probably added by your MTA and you didn't say which MTA you are using.

    I'd recommend sending the mails not by PHP's mail() function but via SMTP, possibly even with SMTP-Auth, using something like PHPMailer.

    0 讨论(0)
  • 2020-11-29 04:49

    See what Google says about this here: http://support.google.com/mail/bin/answer.py?hl=en&ctx=mail&answer=1311182

    All the best!

    0 讨论(0)
  • 2020-11-29 04:54

    @Mujibur is also right, But I used. But Didn't missed Headers too.

    mail($to, $subject, $message, $headers, '-f'.$from_email_address);
    

    And its successful to me, Let's check it from your side.

    0 讨论(0)
提交回复
热议问题