I'm trying to create a form using the php mail() function. The user will enter a name, e-mail, address and a question. When submitted it will send a message to them. I'm trying to create it putting the php code on the same page as the form. I haven't even tested the code yet, because when just viewing the form, some of the php code is displayed on the html page.
Here's my code:
<?
$to = "$_POST['email']";
$subject = "Your Registration";
$body = "Your registration has been received.";
$headers = "From:KenB624@yahoo.com\r\n";
if (mail($to, $subject, $body, $headers))
{
echo("<p>Message has been sent!</p>");
}
else
{
echo("<p>Error! Message delivery attempt failed.</p>");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Also, I would suggest always using the full <?php tag instead of <? to ensure compatibility with any PHP configuration.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Are you running it from your web host or locally from your PC? If the host, does it, in fact, support PHP? If your PC, do you have PHP and a web server installed and running, and are you accessing the page via a "localhost" URL (as opposed to double-clicking the file icon or loading it via the File->Open menu option of the browser)?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
I copied-and-pasted your last version and ran it locally and it seemed to function fine (PHP 5.2.6).
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
One more (hopefully stupid) question, did you give the file a ".php" suffix instead of ".html"?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks