How to remove via and server name when sending mails with PHP?
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!
Hide server when sending email from mail php function
As per the mail()
docs, you use the optional 5th parameter for the function and pass in the name of the server you'd like to masquerade as:
mail($to, $subject, $message, $headers, "-f sender@website.com");
Related Topics
PHP What Is the Best Approach to Using Xml? Need to Create and Parse Xml Responses
Integrating Mailjet API V3 Wrapper as Codeigniter Library
If Singletons Are Bad Then Why Is a Service Container Good
How to Send 500 Internal Server Error Error from a PHP Script
Request Headers Bag Is Missing Authorization Header in Symfony 2
PHP - How to Build Tree Structure List
PHP Cli: How to Read a Single Character of Input from the Tty (Without Waiting for the Enter Key)
Redirecting to Authentication Dialog - "An Error Occurred. Please Try Again Later"
Excel Date Conversion Using PHP Excel
Php: Get N-Th Item of an Associative Array
How to Keep JSON_Encode() from Dropping Strings with Invalid Characters
How to Set a Default Attribute Value for a Laravel/Eloquent Model
Add Fee Based on Specific Payment Methods in Woocommerce
PHP - Plus Sign with Get Query