I have the following phpmailer and have displayed the date by using php echo but the problem is that, if the user were to delete the date, then the date won't work. What is the best way to prevent an user from deleting information displayed in the placeholder?
<?php
ob_start();
include_once __DIR__.'/header2.php';
if(!isset($_SESSION['u_uid'])) {
echo "<meta http-equiv='refresh' content='0;url=index.php?subscribed=notlogin'>";
exit();
} else {
if($_SESSION['u_permission'] == 0) {
echo "<meta http-equiv='refresh' content='0;url=header2.php?subscribed=nopermission'>";
exit();
} else {
$date = strip_tags(date('Y-m-d H:i:s'));
echo '<form action="subscribed_form.php" method="POST"><table class="subscribed">
<tr>
<th colspan="3" class="update_title">Welcome to the Administrator\'s Display Subscribed Newsletter Members\s Section</th>
</tr>';
echo '
<tr>
<th>Newsletter\'s name:</th><td><input type="text" name="name" value="Enter Newsletter\'s Name"></td>
</tr>
<tr>
<th>Newsletter\'s Description:</th><td><textarea name="description" value="Enter Newsletter\'s Description"></textarea></td>
</tr>
<tr>
<th>Newsletter\'s Date:</th><td><input type="text" name="date" value="'.htmlspecialchars($date).'"></td>
</tr>
<tr><th></th><td><input type="submit" name="submit" value="Send Newsletters"></td></tr></table></form>';
}
}
Related
i am currently working on a module where faculty can post attendance to the students by selecting a dropdown(select box) which is generated dynamically by the information given by the faculty.When faculty selects a particular year and section respected student list is retrived and displayed in a table.But the requirement is once the attendance is posted to a particular class/section on a particular it cannot be opened again by the faculty
I have tried using mysql_num_rows() function to check if any rows are already present in the db or not on that particular date.But its not working the way i wanted
here is my entire code of the module excluding db file
<form action="take.php" method="Post">
<br>
<table class="table table-bordered table-hover ">
<tr>
<th>S.no</th>
<th>Student Name</th>
<th>Roll Number</th>
<th>Present</th>
<th>Absent</th>
</tr>
<?php
if (isset($_POST['search']))
{
$stu="Student";
$yr=$_POST['year'];
$se=$_POST['section'];
$subdr=mysql_query("SELECT subject FROM schedule WHERE id='$cuid' AND day='$d' AND class='$yr' AND section='$se'");
$subj=mysql_fetch_assoc($subdr);
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid' AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
$display=mysql_query("select name,id from login where role='$stu' AND academic='$yr' AND section='$se'");
$sno=0;
$count=0;
while ($row=mysql_fetch_array($display)) {
$sno++;
?>
<tr>
<td><?php echo $sno ?></td>
<td>
<?php echo $row['name'] ?>
<input type="hidden" name="name[]" value="<?php echo $row['name'] ?>">
</td>
<td>
<?php echo $row['id'] ?>
<input type="hidden" name="id[]" value="<?php echo $row['id'] ?>">
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Present" required>
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Absent" required>
</td>
</tr>
<?php
$count++;
}
}
?>
<tr>
<td colspan=5>
<center><label><?php echo "Subject : ".$subj['subject']; ?></label></center>
</td>
</tr>
<input type="hidden" name="yr" value="<?php echo $_POST['year']; ?>">
<input type="hidden" name="set" value="<?php echo $_POST['section']; ?>">
<?php
} ?>
</table>
<center><input type="submit" name="submit" value="Submit" class="btn btn-primary" >
</center>
</div>
the expected output should display a message saying "Records posted" based on query like :
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid'
AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
#display the student list
}
Your assignment is:
$dis_date=date("Y-m-d H:i:s");
so $dis_date contains both a date and a time of day. The query will only match if the records in the table have the exact same time of day, not just the same date.
You should leave the time out of the variable:
$dis_date=date("Y-m-d");
If the datatype of the column in the table is DATETIME, you also need to filter out the time from that, with:
AND DATE(ondate)='$dis_date' And subject='$subj_d'"
You don't need to do this if the datatype is DATE.
So i need to create a email form my filename currently is test12.php and the script for emailing the form to my inbox is executing even though i have not pressed the submit button ! here is my code:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
if (!isset($_POST['Submit'])) {
}
?>
<form name="contactform" method="post" action="test12.php" target="success" id="CmForm">
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="first_name" maxlength="50" size="30" placeholder="Enter your first name" required="required">
</td>
</tr>
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="last_name" maxlength="50" size="30" placeholder="Enter your last name" required="required">
</td>
</tr>
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="email" maxlength="80" size="30" placeholder="Enter your email adress" required="required">
</td>
</tr>
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="telephone" maxlength="30" size="30" placeholder="Enter your subject" required="required">
</td>
</tr>
<tr>
<td valign="top">
<textarea class="text-area w-input" name="comments" maxlength="5000" cols="25" rows="6" placeholder="Write message" required="required"></textarea>
</td>
</tr>
<tr>
<input class="submit-button w-button" data-wait="Please wait..." type="submit" value="Submit" onclick='$("#success").show()' onclick='$("#CmForm").hide()'>
</td>
</tr>
</form>
<?php
}
else {
// form engine
echo "<div>Thank you! Your submission has been received!</div>";
}
?>
Also i would like it to display the thank you message after i click submit and make the form itself dissapear! And also how can i make the text boxes smaller? They currently are huge!
Your submit button is not named correctly and thus the check for it fails. Better like this:
<input class="submit-button w-button" data-wait="Please wait..." type="submit" name="Submit" value="Submit" onclick='$("#success").show()' onclick='$("#CmForm").hide()'>
You also might want to move the check if (!isset($_POST['Submit'])) { in a way that the code for form submission is inside the else case of this condition, because otherwise you always get a "died" error message.
Use css to set the width of the textareas.
<style>
.text-area{width: 300px;}
</style>
The reorganized code looks like the following; however there is still room for improvement when handling errors which lead to the "died();" function.
if (!isset($_POST['Submit'])) {
?>
<form name="contactform" method="post" action="test12.php" target="success" id="CmForm">
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="first_name" maxlength="50" size="30" placeholder="Enter your first name" required="required">
</td>
</tr>
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="last_name" maxlength="50" size="30" placeholder="Enter your last name" required="required">
</td>
</tr>
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="email" maxlength="80" size="30" placeholder="Enter your email adress" required="required">
</td>
</tr>
<tr>
<td valign="top">
<input class="text-area w-input" type="text" name="telephone" maxlength="30" size="30" placeholder="Enter your subject" required="required">
</td>
</tr>
<tr>
<td valign="top">
<textarea class="text-area w-input" name="comments" maxlength="5000" cols="25" rows="6" placeholder="Write message" required="required"></textarea>
</td>
</tr>
<tr>
<input class="submit-button w-button" data-wait="Please wait..." type="submit" name="Submit" value="Submit" onclick='$("#success").show()' onclick='$("#CmForm").hide()'>
</td>
</tr>
</form>
<?php
} else {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
// form engine
echo "<div>Thank you! Your submission has been received!</div>";
}
?>
Further improvements to the code would be: Instead of die-ing in "died", show the form with prefilled fields from the submission.
so i am working on a contact form in html and i linked it to a sendmail.php file, as i still in the early process i was testing if fields are empty echo something... nothing is appearing. Please check my code it's still in it's early stage i'm afraid i have missed something out:
HTML
<form action="sendmail.php" method="post" >
<table width="101" border="0">
<tr>
<th scope="col">Full Name:</th>
</tr>
<tr>
<th width="95" scope="col"><input type="text" name="name" id="to" placeholder="Full Name" /></th><!-- -->
</tr>
<tr>
<th scope="row">Telephone:</th>
</tr>
<tr>
<th scope="row"><input type="text" name="telephone" id="telephone"placeholder="Telephone" />
</tr>
<tr>
<th scope="row">Subject:</th>
</tr>
<tr>
<th scope="row"><input type="text" name="subject" id="subject" placeholder="Subject" /></th>
</tr>
<tr>
<th scope="row">Message:</th>
</tr>
<tr>
<th scope="row"><textarea name="body" id="body" cols="45" rows="5" placeholder="Message"></textarea></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><input type="submit" name="submit" id="submit" value="Submit" /></th>
</tr>
</table>
</form>
PHP
<?php
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php/';
$errors = array();
//if values are null echo null values
//in my case i kept null on purpose to see if working
//getting nothing
if(isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body']))
{
echo 'Null values';
}
?>
Your line
if(isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body'])){....}
should be
if(!isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body'])){.....}
On submit input type text are never NULL.
EDIT:
require_once 'libs/phpmailer/PHPMailerAutoload.php/';
Try this?
require_once 'libs/phpmailer/PHPMailerAutoload.php';
You didn't ask to do something as far as I can see.
This might work (all in one file, no need to create a second file)
<?
if($_SERVER['REQUEST_METHOD']=="POST")
{
if(strlen($_POST['name']) == 0)
{ $error_msg ="- Please, provide us with your name.<br>"; }
if(strlen($_POST['*****WHATEVER*****']) == 0)
{ $error_msg ="- Fill in your problem :D.<br>"; }
if(!empty($error_msg))
{
echo "<b>Your message can't be send due to the following reason:</b> <br><br>";
echo $error_msg;
echo "<br>Click on <a href='javascript:history.back(1)'>Go back</a> and provide us with your name.<br><br>";
}
else
{
$recipient = "WHO NEEDS TO RECEIVE???";
$subject = "Subject, can be filled in via input field if you like";
$header = "From: " . $_POST['email'] . "\n";
$mail_body = "Contact script was used on " . date("d-m-Y") . " at " . date("H:i") . "h.\n";
$mail_body .= "Text you like to read:\n";
$mail_body .= "Name: " . $_POST['name'] . "\n";
$mail_body .= "\n\n -- End of contact --";
mail($recipient, $subject, $mail_body, $header);
print "Your mail is sent and whatever you like to tell them ;)";
}
}
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" name="contact">
******Then add your tables and label them as you please.****
Firstly I've searched current thread's and tried 99% of the working fixes provided by the community,
My problem is i am receiving no email's via
www.vapescotts.co.uk
This contact form is placed at the bottom, The odd thing is the website is an altered version of a working website. So I'm clueless to why this version don't work.
<form name="htmlform" method="post" action="html_form_send.php">
<table width="100%">
</tr>
<tr>
<td valign="top">
<label for="first_name"><p>First Name</p></label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="50">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name"><p>Last Name</p></label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="email"><p>Email Address</p></label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone"><p>Telephone Number</p></label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments"><p>Your Comments</p></label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="38" rows="12"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:left">
<input type="image" src="submit.png" input type="submit" value="Submit" height: "251px"; width: "293px"></i>
</td> </td>
</tr></tr>
</table></table>
</form></form>
</div> </div>
And here is the html_form_send.php configuration
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "vapescotts#gmail.com";
$email_subject = "Scotts Custard Cream Enquiry";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for your enquiry, Redirecting back to Scott's Custard Cream.
<br />If you are not redirected automatically,<a href='http://www.vapescotts.co.uk'>Click Here</a>
<meta http-equiv="refresh" content="3;url=http://www.vapescotts.co.uk" />
<?php
}
die();
?>
Thank's again to the StackOverflow Community.
some servers block mail function better to try SMTP PHP Mailer.
Here we go send email using Gmail SMTP server through PHP Mailer
Try this code, might help you out. Edit this code as per your convenience.
$to = "webmaster#example.com";
$subj = "Contact Form Request";
$body = "There is a new contact form report, Kindly check it out.";
$body .= "<table border='1' cellpadding='5'>";
$body .= "<tr><td>Name:</td><td>".$name."</td></tr>";
$body .= "<tr><td>Email:</td><td>".$email."</td></tr>";
$body .= "<tr><td>Subject:</td><td>".$subject."</td></tr>";
$body .= "<tr><td>Message:</td><td>".$msg."</td></tr>";
$body .= "</table>";
$headers = "From: $email" . "\r\n";
$headers .= "Reply-To: " . strip_tags($email) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$succ = mail( $to, $subj, $body, $headers );
if ( $succ || $succ != '' ) {
echo "Mail Sent";
} else {
echo "Failed";
}
How would I create a form in HTML that would email the content of the form to an email? Here is what I have.
<form action="mailto:email#example.com" enctype="text/plain" method="post">
<input name = "subject" placeholder = "Your Name"></input>
<br>
<textarea name = "message" placeholder = "Email Us." style = "height:100px;"></textarea>
<input type="submit" value="Submit" placeholder = "Submit"></input>
</form>
could I do this solely in HTML with the mailto: action? or would i need some php like
mail('email#example.com', $_POST['subject'], $_POST['message']);
Any suggestions?
Please try to use header as well to sending a email.
<?php
$to = 'connormemail#gmail.com';
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: connormemail#gmail.com' . "\r\n";
$retval = mail($to, $subject, $message, $headers);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
So there is all kind of wrong in what I'm about to post. Such as don't use tables to style your forms, etc. But I'm taking this off another site so it'll be simple. What you need is a mix of html for the form and php for the mailing.
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
Email Form
</td>
</tr>
</table>
So there is your basic form.
Here is your basic php. Place it in the same directory as your .html file: send_form_email.php (you must use this filename exactly)
Make sure to edit the parts indicated with your email and subject line.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
If you need to see this tutorial in it's entirety, it's located here:http://www.freecontactform.com/email_form.php
In order to make a custom form it is pretty easy to edit the html and related php elements, but if you don't know any php, etc. I'd just stick to the premade forms.