Guigo: Thanks. I’m working on one using Flash, but I don’t have Flash on this computer so I need to wait a couple more days.
Another thing about this script (as you can see I’m not a mail() expert, truthfully the first time I ever used it was to do this tutorial, but now, me being the loser that I am, I am having fun with it), you know how in Outlook express, or many other mail clients you have those “From, bcc, cc, etc” headers? well the first script I gave you would not say who the e-mail was from. For me it would say “nobody” So to fix that, PHP includes additional headers that can be added. Here is how I add my “From” field and I also added a “BCC” field that sends an e-mail to another one of my accounts, don’t worry… once I was finished testing I removed the BCC field.
Anyway… here is the modified code:
<?
$Subject = "Test E-mail";
$headers = "From: $fromName <$fromName@$SERVER_NAME>
";
$headers .= "bcc: [email]je****[email protected][/email]
";
if(submit == TRUE)
{
mail($toEmail, $Subject, $nMessage, $headers);
}
?>
Self-explanitory right? no? Ok, well here is the explanation of it. I won’t touch $Subject, because we know what that is…So here is an explanation of $headers
$headers = "From: $fromName <$fromName@$SERVER_NAME>
";
$headers .= "bcc: [email]je****[email protected][/email]
";
the first $headers defines the “From:” field. the "
" tells PHP that there is supposed to be a line break (much like < br > in HTML). The second header adds the “bbc” value to the first, so if we were to print the variable $headers like this:
print $headers;
our output would be:
From: name< [email protected] > bcc: je****[email protected]
the “.=” adds strings together.
Ok anyway, Now that our strings are together, we have to place them in the code.
mail($toEmail, $Subject, $nMessage, $headers);
This will fill out the From: header and it wills end a blind copy to my server at school Any questions?
Oh one quick thing, the PHP manual has a great post about using the headers that might help everyone:
Originally posted by Cookieme at http://www.php.net
**$headers .= "From: Name<[email protected]>
";
$headers .= "X-Sender: <[email protected]>
";
$headers .= "X-Mailer: PHP
"; //mailer
$headers .= "X-Priority: 3
"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <[email protected]>
";
//Uncomment this to send html format
//$headers .= "Content-Type: text/html; charset=iso-8859-1
";
//$headers .= "cc: [email protected]
"; // CC to
//$headers .= “bcc: [email protected]”; // separete multiple with commas **
a link to that is: PHP: mail - Manual just scroll down to get to that post.
Cheers guys and girls,
Jubs