I just wrote an emailing page and the From: part of the header is not being evaluated, meaning that the from line of the email is the name of the website. Can anyone tell me why this isn't working?
Relevant code:
Incidentally, the reason I put everything in a function was so I could exit without having the page elements fail to render. Also, the From: header was working before I tweaked some things (not sure what though...).
Thanks in advance.
--Chessbot
"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
Relevant code:
Code:
<?php
function onload()
{
$addrs = $_POST['addrs'];
$names = $_POST['names'];
$fromaddr = $_POST['fromaddr'];
$fromname = $_POST['fromname'];
$subject = $_POST['subject'];
$body = $_POST['body'];
if (!(isset($addrs) && isset($names) && isset($fromaddr) && isset($fromname) && isset($subject) && isset($body)))
return;
$toheaders = "To: ";
for ($i=0; $i<count($addrs); $i++)
{
if ($addrs[$i] == "")
break;
$toheaders .= $names[$i] . " <" .$addrs[$i] . ">";
if ($addrs[$i+1] != "")
$toheaders .= ", ";
}
$toheader .= "\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= $toheaders . "\r\n";
$headers .= "From: $fromname <{$fromaddr}>\r\n";
if (!mail($tostring, $subject, $body, $headers))
echo "There was an error in the email.";
else
echo "Message sent!";
}
onload();
?>
Incidentally, the reason I put everything in a function was so I could exit without having the page elements fail to render. Also, the From: header was working before I tweaked some things (not sure what though...).
Thanks in advance.
--Chessbot
"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series