I found a link to a site that had a php code that would allow someone to send email directly from an HTML form. I slightly altered the code and I
am having a bit of a problem. first, the code:
[code=php]<?PHP
$to = “[email protected]”;
$subject = “website”;
$header = “lyla.com”;
$date = date (“l, F jS, Y”);
$time = date (“h:i A”);
$msg = “New message from [url]www.lyla.com[/url] submitted on $date at $time.nn”;
if ($_SERVER[‘REQUEST_METHOD’] == “POST”) {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}
mail($to, $subject, $msg, $header);
if(mail($to, $subject, $msg, $headers) == “true”)
{
echo(“Your message has been sent <br />Click <a href=”http://www.lyla.com”>Here</a> to return to the Homepage.”);
}
else
{
echo(“Sorry, due to a technical error, your message has not been sent”);
}
?>
My problem lies in the last “if” statement. Each time the form is submitted, 2 emails appear in the mail box. I know this is because PHP sees the mail command in the “if” statement as something that it should execute, but when I use: “if ( mail() == “true”)” the script will not function.
Please let me know if there’s a better way to pull this off.
Thank you