Advanced Form to Email PHP contact form script
Form to email forms are the easiest way to let the visitor contact you, the visitor can inform you without revealing your email address on the web page, i have used this php form script, it's 100% working and advanced, These can be really useful in your own projects, as well as projects for clients
Step 01
Use table to align form contents and style it adding some css,
Step 02
Change the email address
Step 03
copy and past this code and save it as index.php (you can change the filename to anything you like)
Step 04
Save this script as captcha.php
Step 05
Create A Folder In cPanel name it "fonts"
Step 06
Upload "georgia.ttf" font into folder that you created
Step 01
Use table to align form contents and style it adding some css,
Step 02
Change the email address
Step 03
copy and past this code and save it as index.php (you can change the filename to anything you like)
<?php
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div class="formwithattach">
<?php
if(isset($_POST['submit'])) {
$errors = array();
if($_POST['name'] == "") {
$errors[] = 'The name field is empty';
}
if($_POST['address'] == "") {
$errors[] = 'The address field is empty';
}
if($_POST['contact'] == "") {
$errors[] = 'The Contact field is empty';
}
if($_POST['email'] == "") {
$errors[] = "The email field is empty";
}
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$errors[] = "The email address was not valid";
}
if($_POST['subject'] == "") {
$errors[] = "Please enter your subject";
}
if($_POST['likeit'] == "") {
$errors[] = 'The like field is empty';
}
if($_POST['comment'] == "") {
$errors[] = "The comment field is empty";
}
if ($_REQUEST['captcha_entered']!=$_SESSION['rand_code']) {
$errors[] = "The math is incorrectly";
}
if(count($errors) == 0) {
$sendto = "sritvnewsit@gmail.com";//Your email goes here
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$address = filter_var($_POST['address'], FILTER_SANITIZE_STRING);
$contact = filter_var($_POST['contact'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
$website = filter_var($_POST['website'], FILTER_SANITIZE_STRING);
$subject = $_POST['subject'];//You can change your subject here
$likeit = filter_var($_POST['likeit'], FILTER_SANITIZE_STRING);
$qua_1 = filter_var($_POST['qua_1'], FILTER_SANITIZE_STRING);
$qua_2 = filter_var($_POST['qua_2'], FILTER_SANITIZE_STRING);
$qua_3 = filter_var($_POST['qua_3'], FILTER_SANITIZE_STRING);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
$message = "<strong>$name</strong> has sent you a message:
<p><strong>Name:</strong> <em>$name</em></p>
<p><strong>Address:</strong> <em>$address</em></p>
<p><strong>Contact:</strong> <em>$contact</em></p>
<p><strong>Email:</strong> <em>$email</em></p>
<p><strong>Social Network:</strong> <em>$website</em></p>
<p><strong>The subject:</strong> <em>$subject</em></p>
<p><strong>Gender:</strong> <em>$likeit</em></p>
<p><strong>Education Qualifications :</strong> <em>$qua_1</em></p>
<p><strong>Profetional Qualifications:</strong> <em>$qua_2</em></p>
<p><strong>Experience:</strong> <em>$qua_3</em></p>
<p><strong>Message:</strong> <em>$comment</em></p>";
$headers = "From: $name <$email> \r\n";
$headers .= "X-Mailer:PHP/\r\n";
$headers .= "MIME-Version:1.0\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
if(mail($sendto, $subject, $message, $headers)) {
$success = true;
} else {
$success = false;
}
} else {
$success = false;
}
}
if(isset($_POST['submit'])) {
if($success == true & count($errors) == 0) {
echo "<script>alert('Thank you for your email $name,
we will get back to you as soon as posible.');</script>";
}
if(count($errors) == 0 & $success == false & isset($_POST['submit'])) {
echo "<h2>There was a problem with our form. Please email us </h2>";
}
if($success == false & count($errors) > 0 & isset($_POST['submit'])) {
echo '<ul>';
foreach($errors as $show_all) {
echo '<li><span style="color:#ff0000;">'.$show_all.'</span></li>';
}
echo '</ul>';
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data">
<table><tr><td><b>Vacancy:</b></td><td><select name="subject">
<option value=""> -- Please select -- </option>
<option>Marketing Excutives</option>
<option>Assistant art derector</option>
<option>Camaraman</option>
<option>programme producer</option>
<option>MCR Assistants</option>
<option>Video Editors</option>
<option>Makeup Artists</option>
<option>MCR Assistants</option>
<option>Presenters</option>
<option>Account Clerk</option>
<option>News Reader - Sinhala</option>
<option>News Reader - Tamil</option>
<option>Presenters</option>
<option>Drivers</option>
<option>Office Maintain Persons</option>
<option>Hardware and Network Admin</option>
<option>Other</option>
</select></td></tr>
<tr><td><b>Your Name:</b> </td>
<td><input name="name" type="text" size="31" id="name" /></td></tr>
<tr><td><b>Your Address:</b></td><td>
<textarea name="address" rows="2" cols="24"></textarea></td></tr>
<tr><td>
Contact No: </td>
<td><textarea name="contact" cols="24" rows="2" id="contact"></textarea></td></tr>
<tr><td><b>E-mail:</b> </td><td><input name="email" type="text" size="31" />
</td></tr>
<tr>
<td>Social Network:</td>
<td><input name="website" type="text" size="31" placeholder="www.facebook.com/rad">
</td></tr>
<tr>
<td>Gender</td><td>
<input type="radio" name="likeit" value="male" checked="checked" />
Male
<input type="radio" name="likeit" value="female" />
Female</td></tr>
<tr>
<td><b>Education Qualifications</b></td><td>
<textarea name="qua_1" rows="4" cols="24" id="qua_1"></textarea></td></tr>
<tr>
<td><p><b>Profetional Qualifications</b></p></td><td>
<textarea name="qua_2" rows="4" cols="24" id="qua_2"></textarea></td></tr>
<tr>
<td><b>Experience:</b></td>
<td>
<textarea name="qua_3" rows="4" cols="24" id="qua_3"></textarea></td></tr>
<tr>
<td><b>Other Details:</b></td>
<td>
<textarea name="comment" rows="4" cols="24" id="comment"></textarea></td></tr>
<tr><td>Security Code:</td>
<td> <?php echo '<img src="captcha.php" />'; ?>
<input name="captcha_entered" type="text" id="captcha_entered" size="10"
maxlength="2"
placeholder="Write total here"/> <input type="hidden" name="captcha_total"
id="captcha_total" value="<?php echo $_SESSION['rand_code']; ?>" /></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Send "></td></tr></table>
</form></div>
</body>
</html>
Step 04
Save this script as captcha.php
<?php
session_start();
$num1=rand(1,9);
//Generate First number between 1 and 9
$num2=rand(1,9);
//Generate Second number between 1 and 9
$captcha_total=$num1+$num2;
$math = "$num1"." + "."$num2"."=";
$_SESSION['rand_code'] = $captcha_total;
$dir = 'fonts/';
$image = imagecreatetruecolor(120, 25);
//Change the numbers to adjust the size of the image
$black = imagecolorallocate($image, 255, 255, 255);
$color = imagecolorallocate($image, 200, 100, 90);
$white = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image,0,0,4,399,$white);
imagettftext ($image, 20, 0, 20, 25, $color, $dir."georgia.ttf", $math );
//Change the numbers to adjust the font-size
header("Content-type: image/png");
imagepng($image);
?>
Step 05
Create A Folder In cPanel name it "fonts"
Step 06
Upload "georgia.ttf" font into folder that you created
That's it !
Advanced Form to Email PHP contact form script
Reviewed by Unknown
on
12:37 AM
Rating:
No comments: