PHP EMAIL FORM HELP NEEDED

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rohit78k
Forum Newbie
Posts: 1
Joined: Tue May 18, 2010 9:36 am

PHP EMAIL FORM HELP NEEDED

Post 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.
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: PHP EMAIL FORM HELP NEEDED

Post by timWebUK »

You will want to use regular expressions to check emails, some research on Google should help you.
Post Reply