3/25/2017 - 9:27 PM

Contact form

Contact form

// declare values
$contact_email = $_POST['EmailAddress'];
$contact_subject = $_POST['Subject'];
$contact_name = $_POST['FullName'];
$contact_message = $_POST['Message'];
$mydate = date ( 'l, F d Y g:i A',time()+240 );
$contact_firstname = $_POST['FirstName'];
$option = $_POST['radio']; 
$dropdown = $_POST['drop_down'];

foreach($_POST['check'] as $value) { 
$check_msg .= "Checked: $value\n"; 
// $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

// where to send e-mail to
$to = 'user@mydomain.com';

// e-mail subject
$subject = "Message submitted using Contact Us form";

// e-mail message
$message = "You have received a contact message:\r\n"

."Contact Name: $contact_name\r\n"
."Subject: $contact_subject\r\n"
."Submitted: $mydate\r\n"
."From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Message: $contact_message\r\n"
."First name: $contact_firstname\r\n"
."Option: $option\r\n"
."Drop-Down: $dropdown\r\n"
."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";

$headers = "From: $contact_name <$contact_email>\n"
."Reply-To: $contact_email\n"
."X-Mailer: PHP/".phpversion();

// check for validation, then send the e-mail
if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_message)) {
echo '<p>Send us a message, enter your information below and click \'Submit\'!</p>
<form method="post" action="">
<table id="Form-Details">
<tr><td>Name:</td><td><input type="text" name="FullName" size="20" /></td>
<td>Subject:</td><td><input type="text" name="Subject" size="20" /></td></tr>
<tr><td>Email:</td><td colspan="3"><input type="text" name="EmailAddress" size="20" /></td></tr>
<tr><td colspan="4">Message:</td></tr>
<tr><td colspan="4"><textarea rows="6" name="Message" cols="47" class="input"></textarea></td></tr>
<tr><td colspan="4" class="right1"><input type="submit" value="Submit" /><input type="reset" value="Reset" /></td></tr>
} elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
echo "<p>ERROR: Please enter a valid e-mail address.</p>";
} else {
mail( $to, $subject, $message, $headers );
echo "<h3>Message Sent!</h3><p>Dear $contact_name,<br /><br />We will get back to you as soon as possible using $contact_email.";