Page 1 of 1

PHP EMAIL FORM HELP NEEDED

Posted: Tue May 18, 2010 9:45 am
by rohit78k
Hi following is the code for my contact page...
this is contact.php file and it calls another file sendmail.php.

<div class="contactform">

<form action="sendmail.php" method="post">

<p><label for="name">Name:</label>
<input class="inputbox" name="name" type="text" value="
%% addToOutput($_POST['name']); %%
"></p>

<p><label for="email">Email:</label>
<input class="inputbox" name="email" type="text" value="
%% addToOutput($_POST['email']); %%
"></p>

<p><label for="telephone">Telephone:</label>
<input class="inputbox" name="telephone" type="text" value="
%% addToOutput($_POST['telephone']); %%
"></p>

<p><label for="message">Message:</label>
<input type="hidden" name="message" value="Message: ">
<textarea name="message" cols="42" rows="6">
%% addToOutput($_POST['Message']); %%
</textarea></p>

<br>

<p><input class="button submitbutton" type="submit" value="Submit" name="submit"></p>


</form>

</div> <!-- contactform div ends -->

----------------------------------------------------
sendmail.php
-----------------------------------------------------
<?php

if(isset($_POST['submit'])) {

$to = "rohit78k@yahoo.co.uk";
$subject = "Website Enquiry";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$telephone_field = $_POST['telephone'];
$message_field = $_POST['message'];

$body = "Website Enquiry from:\n\n Name: $name_field\n Email: $email_field\n Telephone: $telephone_field\n\n\n Message: $message_field";


$match = "/(bcc:|cc:|content\-type:)/i";

if (preg_match($match, $from) ||
preg_match($match, $subject) ||
preg_match($match, $body)) {
die("Header injection detected.");
}


mail($to, $subject, $body, "from: rohit78k@yahoo.co.uk");

Header ("Location:index.php?page=ContactFormThanks");

} else {

die("Direct access not allowed!");

}

?>
----------------------------------------
How to apply checks on email and phone number please guide as i am not getting any clue.

Re: PHP EMAIL FORM HELP NEEDED

Posted: Tue May 18, 2010 10:15 am
by timWebUK
You will want to use regular expressions to check emails, some research on Google should help you.