PHP form sending through email
Hi Guys/gals
Recently bought a template so i could start learning and create my first site, but i have come stuck on the Feeback form.
I know how to get introduce the mailto: code to send email, but what i really want is a php code to do it for me. here is what i have so far.
Form Code:
<form id="ContactForm" action="form.php" method="post">
<div>
<label><span class="input"><input type="text" value="Name:" onBlur="if(this.value=='') this.value='Name:'" onFocus="if(this.value =='Name:' ) this.value=''" /></span></label>
<label><span class="input"><input type="text" value="E-mail:" onBlur="if(this.value=='') this.value='E-mail:'" onFocus="if(this.value =='E-mail:' ) this.value=''" /></span></label>
<label><span class="input"><input type="text" value="Subject:" onBlur="if(this.value=='') this.value='Subject:'" onFocus="if(this.value =='Your Country:' ) this.value=''" /></span></label>
<span class="textarea"><textarea onBlur="if(this.value=='') this.value='Your Message:'" onFocus="if(this.value =='Your Message:' ) this.value=''" >Your Message:</textarea></span>
</div>
<div class="alignright">
<a href="#" class="link" onClick="document.getElementById('ContactForm').reset()"><span><span>clear</span></span></a>
<a href="#" class="link" onClick="document.getElementById('ContactForm').submit()"><span><span>send</span></span></a>
</div>
</form>
And here is the PHP:
<?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
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("email@person.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
}
else
{//if "email" is not filled out, display the form
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
Can someone plase let me know where i am going wrong.
Thanx in advance.
Pedro
