How can I Mail from

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

How can I Mail from

Post by mariolopes »

Hi
I want to email a message but how can i define the sender of the message. I use the following command

Code: Select all

 
mail( $to, $subject, $message );
 
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: How can I Mail from

Post by pbs »

Use headers

Code: Select all

 
mail($to, $subject, $message, $headers);
 
Also refer http://php.net/manual/en/function.mail.php
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: How can I Mail from

Post by Apollo »

Adding the -f flag will do the trick:

Code: Select all

$from = "your.address@somewhere.com";
$to = "yourmomma@hotmail.com";
$subject = "Hello";
$body = "Hi mum, how are you?";
$header = "From: $from\r\n";
$flag = "-f$fromAddress";
 
mail($to,$subject,$body,$header,$flag);
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: How can I Mail from

Post by mariolopes »

works perfect
Thank you guys
Post Reply