I'm really new to PHP. I would like to try to figure this out on my own, but I need this PHP email form up and running as soon as I can get it. I've been reading information here: http://www.w3schools.com/PHP/php_mail.asp
Only problem is, it's not working, at all. Here's my PHP script:
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['email']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("example@example.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
}
else
{
echo "<form method='post' action='mailform.php'>
<table>
<tr><td align="right"><b>Email:</b></td> <td><input name='email' type='text' /></td></tr>
<tr><td align="right"><b>Subject:</b></td> <td><input name='subject' type='text' /></td></tr>
<tr><td valign="top"><b>Message:</b></td> <td><textarea name='message' rows='15' cols='40'></textarea></td></tr>
<tr><td></td><td><input type='submit' /></td></tr>
</table>
</form>";
}
?>
That is what is embedded in my contact page. First question, what is the 'mailform.php' supposed to look like?
Whenever you hit submit, it does nothing. Doesn't even send me to a 404 page saying 'mailform.php' doesn't exist.
I've been looking around in forums, and reading tutorials, but everything I read, I get more confused. I have no clue how to do this. If anyone knows of a good tutorial, or cheat sheet site, or something, that would be awesome. I'm so flustered, and have been trying to figure this out for a few hours now.
Another problem I'm having when the form displays on my site. I have a feeling that php isn't configured correctly. Here's a snapshot. The formatting looks like I want it to, but the last few characters of the php are showing up ("; } ?>). I'm not sure why that is.