Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change default mailed by : address in php mail()

Tags:

php

i have the following code

$subject = "Subject Here";  
$headers  = 'MIME-Version: 1.0' . "\r\n";   
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers       
$headers .= 'From: Domain Name <[email protected]>' . "\r\n";           
$to = $email;
$body = '
My Message  here
';
mail($to, $subject, $body, $headers);

and it send mail correctly but when i see details in the email in gmail ... it shows

from Domain Name to [email protected] date Tue, May 25, 2010 at 12:41 PM subject my subject here mailed-by mars.myhostingcompany.net

while i want to show my own address in mailed by section so that it should be mydomain.com instead of mars.myhostingcompany.net

like image 906
Web Worm Avatar asked May 25 '10 19:05

Web Worm


People also ask

What is the correct syntax of mail () function in PHP?

"\r\n"; mail($to,$subject,$message,$headers);

Which PHP function is called to send mail?

PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters.


1 Answers

There are two types of sender (From), the MIME header sender and the envelope sender.

You send the MIME sender with in the headers in the 4th parameter of the mail() function. You are doing this fine.

The enveloper sender (the one you can send when sending email through sendmail or a sendmail compatible wrapper) with the -f flag, is set in the 5th mail() parameter, additional_parameters, in the format you'd pass it on the command line: [email protected].

So your mail function would end up looking like this:

mail($to, $subject, $body, $headers, "[email protected]");
like image 86
LeonardChallis Avatar answered Oct 03 '22 08:10

LeonardChallis