Thread: Mail Editor
View Single Post
Old 07-12-2005, 01:41 PM   #6 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Quote:
The sender address it's shown strange.
PHP Code:
$headers .= "From: \"".$name."\" <"$from">\r"
Your header definition is your flaw here, the from should be:
PHP Code:
$headers .= "From: \"".$name."\" <".$from.">\r\n"
Any line in your header should be formed with a \r\n as your End Of Line. Only the very last line in the header shouldn't have a newline char.
Something like this:
PHP Code:
<?
$name 
stripslashes($_POST['name']);
$from stripslashes($_POST['from']);
$to stripslashes($_POST['to']);
$subject stripslashes($_POST['subject']);
$message stripslashes($_POST['message']);
$headers .= "From: \"".$name."\" <".$from.">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
if(
mail($to,$subject,$message,$headers)){
    echo 
"Mail has been sent.";
}
else{
    echo 
"Mail has not been sent.";
}
?>
Quote:
And one more question.Can I change the order of the variables when it's sending mail? Ex. instead of
PHP Code:
if(mail($to,$subject,$message,$headers
to be like this
PHP Code:
if(mail($headers ,$to$subject,$message
In short NO Since you can form your header any way you want to, the php-mailer needs to know exactly what to address and what subject to parse onto sendmail (or what ever mailerdeamon the system is running) there for the very first argument to mail() must be a correct address to send teh mail to, adn the second argument must be a type of orriginal header.
You shipped header can be formed in any way you like, it will only fool the recieving mail-client, telling it what you told your sending mail-server to ship as the header, in order to disguise any not intended orriginated address, if your sender usualy stamps teh outgoing messages with From: Average joe <joe.barneby@mydomain.com> but you want an intentional reply from the reciever to munge up in your usual <info@mydomain.com> address, and not be send to your usual login name joe.barneby . Then you form the header with that info, the php-mailer then forges the outgoing message to be orriginated from the info sender, instead of the mailer-deamons usual task of fetching the current caller-ID from the login-pool.

An example of that could be:
PHP Code:
$header "From: Mailform <noreply@{$_SERVER['SERVER_NAME']}>\r\n";
$header =."Reply-To: <" stripslashers($_POST['from']) .">\r\n";
$header =. "X-Mailer: PHP/" phpversion();
mail(stripslashes($_POST['to']), stripslashes($_POST['subject']),
        
stripslashes($_POST['message'], $header); 
Now the mail that is beeing send, tells the recievers email program that it orriginates from your Mailform, but on replys it should send it to the posted email the submitter posted, yet the server running on your site might be running as 'www' yet noone will ever know that.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote