Form contents not showing in email - php

This is a followup to a question I posted yesterday. I thought everything was working fine, but today, I am not getting any results in the email from the drop down field.
Here is the form code in question:
<form method="post" action="contact.php" name="contactform" id="contactform">
<fieldset>
<legend>Please fill in the following form to contact us</legend>
<label for="name"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="company">Company</label>
<input name="company" type="text" id="company" size="30" value="" />
<br />
<label for="email"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="purpose"><span class="required">*</span> Purpose</label>
<select name="purpose" id="purpose" style="width: 300px; height:35px;">
<option value="none selected" selected="selected">-- Select One --</option>
<option value="I am interested in your services">I am interested in your services!</option>
<option value="I am interested in a partnership">I am interested in a partnership!</option>
<option value="I am interested in a job">I am interested in a job!</option>
</select>
<br />
<label for=comments><span class="required">*</span> Comments</label>
<textarea name="comments" cols="40" rows="3" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Please help us control spam.</p>
<label for=verify accesskey=V> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />
</fieldset>
</form>
It is then processed in PHP and should output the selected option to an email, however the Reason for Contact line always comes through with nothing in it.
Here is the PHP code:
<?php
if(!$_POST) exit;
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$purpose = $_POST['purpose'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
exit();
} else if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "myname#email.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name.\r\n\n";
$e_company = "Company: $company\r\n\n";
$e_content = "Comments: \"$comments\"\r\n\n";
$e_purpose = "Reason for contact: $purpose\r\n\n";
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = $e_body . $e_content . $e_company . $e_purpose . $e_reply;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
}
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
Any assistance would be greatly appreciated. Thanks!

It really looks like it should work, so I'd verify the dumbly obvious stuff: is your <select> tag contained within the <form> tag? Is 'purpose' mis-typed somewhere (it all looks good here, from what I can see)?
What happens if you do print_r($_POST)?
What happens if you do var_dump($purpose) after it is initialized?

Did you check if the server is able to send emails?
Check if sendmail actually works on your server before trying to debug your code (that seems to be good).

Related

How to make checkbox info append to email

I have 3 checkboxes on my contact form. The form works with exception to the checkboxes.. The boxes are selectable but once hitting the "submit" button the selection shows up on the "Thank you for you comment" page. I cannot figure out how to get the checkbox selection to appear in the actual email.
I have tried all sorts of php functions that I have found people to be using in forums and tutorials. Nothing appends the checkbox info to the email. I can't seem to find anyone who knows how to do this.
The 'implode' function does not work. The 'echo' function does not work. The 'array' function does not work. What could be going on?
Here is my html:
<section class="contact">
<form id="contact" action="html_form_send.php" method="post">
<fieldset title="About you">
<legend><span>About you</span></legend>
<label for="name">Name</label>
<input type="text" name="name" id="name" tabindex="10" class="txtinput" placeholder="Your name" required>
<label for="email">Email</label>
<input type="email" name="email" id="email" tabindex="20" class="txtinput" placeholder="valid email" required>
</fieldset>
<fieldset title="Your turn">
<legend><span>Your turn</span></legend>
<p>What, exactly then, are you after?</p>
<div>
<div class="tag">Checkbox1</div>
<input type="checkbox" id="checkbox-1-1" name="option[ ]" class="regular-checkbox big-checkbox" value="salvation" /></input><label for="checkbox-1-1"></label>
</div>
<div>
<div class="tag">Checkbox2</div>
<input type="checkbox" id="checkbox-2-1" name="option[ ]" class="regular-checkbox big-checkbox" value="question" /><label for="checkbox-2-1"></label>
</div>
<div>
<div class="tag">Checkbox3</div>
<input type="checkbox" id="checkbox-3-1" name="option[ ]" class="regular-checkbox big-checkbox" value="other" /><label for="checkbox-3-1"></label>
</div>
<label for="comment" class="inline"></label>
<label for="discourse">Write your comments here</label>
<textarea id="discourse" name="discourse" tabindex="30" class="txtinput" rows="7" placeholder="This is where your thoughts go">
</textarea>
<section id="buttons">
<input type="reset" name="reset" id="resetbtn" class="resetbtn" value="Reset">
<input type="submit" name="submit" id="submitbtn" class="submitbtn" tabindex="40" value="Send away!">
<br style="clear:both;">
</section>
Here is my php:
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "email#email.org";
$email_subject = "website feedback";
function died($error) {
// your error code can go here
echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['discourse'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$discourse = $_POST['discourse']; // 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,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($discourse) < 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 .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($discourse)."\n";
if(isset($_POST["submit"])) //Checks if the send button is pressed
{
echo $_POST["name"]; //print your name
echo $_POST["email"]; //print your email
//check all the checkboxes if anyone is checked. this is a lot of work to do.
//All checkboxes are checked one by one
if(isset($_POST["salvation"]))
echo $_POST["salvation"];
if(isset($_POST["question"]))
echo $_POST["question"];
if(isset($_POST["other"]))
echo $_POST["other"]; }
if(isset($_POST["submit"])) //Checks if the send button is pressed
{
echo $_POST["name"]; //print your name
echo $_POST["email"]; //print your email
if(isset($_POST["option"])) //checks if any interest is checked
{
foreach($_POST["option"] as $value) //Iterate the interest array and get the values
{
echo $value; //print the values } } }
// 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 -->
<script language="javascript" type="text/javascript">
alert('Thank you for contacting us.');
window.location = 'feedbackform.html';
</script>
<?php
die();
?>
<div class="tag">Checkbox2</div>
<input type="checkbox" id="checkbox-2-1" name="option1" class="regular-checkbox big-checkbox" value="yes" /><label for="checkbox-2-1"></label>
</div>
Try naming each option checkbox then retrieve them as follows:
if(isset($_POST['option1']) && $_POST['option1'] == 'yes'){
echo "Yes, this was checked";
}else{
echo "No, this wasn't checked";
}
What that if statement does is checks if that option is set, meaning has value, and grabs the value if it is set. Then it outputs accordingly

Issues with php verification script

I'm not very familiar with PHP. In the past I have been able to read and fix small problems using PHP but this one is giving me quite lot of trouble.
I have a form with two entry boxes, one for email and one for message.
Now, Im trying to add another box to the form to verify human access for anti-spam purposes.
This is the code which I can't make the verification process go through.
//create ramdom numbers
<?php
$num1 = rand(0,9);
$num2 = rand(0,9);
?>
<?php
$error = '';
$email = '';
$comments = '';
$verify = '';
if(isset($_POST['contactus'])) {
$email = $_POST['email'];
$comments = $_POST['comments'];
$app = $_SERVER["REQUEST_URI"];;
if(trim($comments) == '') {
$error = '<div class="error_message">Attention! Please enter your message.</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Attention! Please enter a valid email address.</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
}
//This is where Im having problem. From this point the form doesn't go on.
if(trim($verify) == '') {
error( '<div class="error_message">Attention! Please enter the verification number.</div>');
} else if(trim($verify) != $verify_result) {
error( '<div class="error_message">Attention! The number you entered is incorrect.</div>');
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "info#myaddress.com";
$e_subject = 'You\'ve been contacted from an app web page ' . $name . '.';
$e_body = "You have been contacted using the app comments box on the above app web page, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
$e_reply = "$name $email";
$msg = $e_body . $e_content . $e_reply;
mail($address, $e_subject, $msg, $app, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
// Email has sent successfully, echo a success page.
echo "<div id='success_page_apps'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you, your message has been submitted to us.</p>";
echo "</div>";
echo '<input type="button" value="Send Another" onClick="history.go(-1); return (true); ">';
}
}
if(!isset($_POST['contactus']) || $error != '') {
<?php echo $error; ?>
<fieldset id="contact_apps">
<form method="post" action="#ContactForm">
<label for="email" accesskey="E"><span class="required"></span> Email</label>
<input name="email" type="text" id="email" size="33" value="<?php echo$email;?>"/>
<textarea name="comments" cols="50" rows="15" id="comments"><?php echo$comments;?></textarea>
//This is the 'Are you human?' message
<p><span class="required">*</span> Are you human?</p>
<label class="numbersq" for='verify' accesskey='V'><?php echo $num1; ?> + <?php echo $num2; ?> =</label>
<input class="numbersa" name="verify" type="text" id="verify" size="4" value=""/>
<input name="verify_result" type="hidden" size="4" value="<?php echo $num1+$num2; ?>" /><br />
<input name="contactus" type="submit" class="send" id="contactus" >
</form>
</fieldset>
}
?>
Please note the 'Are you human' message and the conditionals I have in the script which is where I think I'm doing something wrong.
You've forgotten to pull the verify values from the form ... and you have a few other simple errors in there too which I've addressed.
//create ramdom numbers
<?php
$num1 = rand(0,9);
$num2 = rand(0,9);
?>
<?php
$error = '';
$email = '';
$comments = '';
$verify = '';
if(isset($_POST['contactus'])) {
$email = $_POST['email'];
$comments = $_POST['comments'];
$app = $_SERVER["REQUEST_URI"];;
if(trim($comments) == '') {
$error = '<div class="error_message">Attention! Please enter your message.
</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Attention! Please enter a valid email address.
</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
}
//This is where Im having problem. From this point the form doesn't go on.
$verify_result= $_POST['verify_result'];
$verify = $_POST["verify"];
if(trim($verify) == '') {
$error = '<div class="error_message">Attention! Please enter the verification number.</div>';
} else if(trim($verify) != $verify_result) {
$error = '<div class="error_message">Attention! The number you entered is incorrect.</div>';
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "info#myaddress.com";
$e_subject = 'You\'ve been contacted from an app web page ' . $name . '.';
$e_body = "You have been contacted using the app comments box on the above app web page, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
$e_reply = "$name $email";
$msg = $e_body . $e_content . $e_reply;
// mail($address, $e_subject, $msg, $app, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
// Email has sent successfully, echo a success page.
echo "<div id='success_page_apps'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you, your message has been submitted to us.</p>";
echo "</div>";
echo '<input type="button" value="Send Another" onClick="history.go(-1); return (true); ">';
}
}
if(!isset($_POST['contactus']) || $error != '') {
echo $error; ?>
<fieldset id="contact_apps">
<form method="post" action="#ContactForm">
<label for="email" accesskey="E"><span class="required"></span> Email</label>
<input name="email" type="text" id="email" size="33" value="<?php echo$email;?>"/>
<textarea name="comments" cols="50" rows="15" id="comments"><?php echo$comments;?></textarea>
//This is the 'Are you human?' message
<p><span class="required">*</span> Are you human?</p>
<label class="numbersq" for='verify' accesskey='V'><?php echo $num1; ?> + <?php echo $num2; ?> =</label>
<input class="numbersa" name="verify" type="text" id="verify" size="4" value=""/>
<input name="verify_result" type="hidden" size="4" value="<?php echo $num1+$num2; ?>" /><br />
<input name="contactus" type="submit" class="send" id="contactus" >
</form>
</fieldset>
<?PHP
}
?>

Issue with one page site contact form

i have a one page portfolio with a contact form, i have been trying to troubleshoot this thing but have not succeeded. I am no PHP expert so I will try to explain as best as I can. Basically what I have is a contact template file from word press that i have used in the past, but what i want to do is (if possible) implement in my portfolio. My main issue is that when I preview my site in the browser it shows the PHP code that is on the form.
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
// Check fields for errors
if (empty($_POST["txtName"])) {
$errors["txtName"] = "Please enter your name.";
}
if (empty($_POST["txtPhone"])) {
$errors["txtPhone"] = "Please enter your phone number.";
}
if (empty($_POST["txtEmail"])) {
$errors["txtEmail"] = "Please enter your email address.";
} else {
if (!eregi('^[[:alnum:]][a-z0-9_\.\-]*#[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST["txtEmail"])))) {
$errors["txtEmail"] = "Please provide a valid email address.";
}
}
if (count($errors) < 1) {
$to = "test-email#gmail.com";
$subject = 'Bave Designs Contact';
$headers = "From:" . $_POST["txtEmail"] . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<html><body style="font-family:Arial, Helvetica, sans-serif; font-size:12px;">';
$message .= '<p><strong>Name:</strong> ' . $_POST["txtName"] . '<br />
<strong>Phone:</strong> ' . $_POST["txtPhone"] . '<br />
<strong>Email:</strong> ' . $_POST["txtEmail"] . '<br />
<strong>Message:</strong><br />' . $_POST["txtComment"] . '</p>
</body>
</html>';
if ( !mail($to,$subject,$message,$headers) ) {
$errors["send"] = "There was a problem sending your message. Please try again.";
}
}
}
<div id="contact-form">
<?php
if (count($errors) > 0) {
echo '<ul style="color:red; padding:0 0 18px 22px;">';
foreach ($errors as $error) {
echo "<li>" . $error . "</li>";
}
echo "</ul>";
}
?>
<?php if ($_SERVER['REQUEST_METHOD'] == "POST" && count($errors) < 1) { ?>
<p class="success-message"><?php _e('Thank you! Your message has been sent.'); ?></p>
<?php } else { ?>
<form id="contact1" method="post" action="#message" class="contact-form">
<p><label for="txtName">Name</label>
<input type="text" id="txtName" name="txtName" class="field" size="40" value="<?php echo $_POST['txtName'] ?>" /></p>
<p><label for="txtPhone">Phone</label>
<input type="text" id="txtPhone" name="txtPhone" class="field" size="40" value="<?php echo $_POST['txtPhone'] ?>" /></p>
<p><label for="txtEmail">Email</label>
<input type="text" id="txtEmail" name="txtEmail" class="field" size="40" value="<?php echo $_POST['txtEmail'] ?>" /></p>
<p><label for="txtComment">Message</label>
<textarea name="txtComment" id="txtComment" class="field" cols="40" rows="10"><?php echo $_POST['txtComment'] ?></textarea></p>
<p><input type="submit" id="btnSubmit" name="btnSubmit" class="button" value="Submit" /></p>
</form>
<?php } ?>
</div><!-- CONTACT FORM ENDS-->
I switched the wp_mail function to mail which I know is correct.
Any help would be appreciated.
Thanks in advance.
My main issue is that when I preview my site in the browser it shows
the PHP code that is on the form.
So, if I understand correctly, your PHP codes are being shown in your page?
If that is the case, I urge you to contact your webhosting provider asap, because there seems to be a big problem with your Apache configuration.

Send php email from contact form

Hi i am a newbie to php and am following this tutorial
http://tutorialpot.com/2011/06/fancy-contact-form-with-inline-validation/#comment-1771
i am wondering where do i put in my email address so users can send a email to me
thanks in advance
<?php
function checkLen($str,$len=2) //&len definens the minimun length of the input fields
{
return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
}
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[#][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
foreach($_POST as $k=>$v)
{
$_POST[$k]=stripslashes($_POST[$k]);
$_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}
//session names must be same with that in contact form
session_name("tpot_contact");
#session_start();
if (isset($_POST['send'])){
$err = array();
if(!checkLen('name'))
$err[]='The name field is too short or empty!';
if(!checkLen('email'))
$err[]='The email field is too short or empty!';
else if(!checkEmail($_POST['email']))
$err[]='Your email is not valid!';
if(!checkLen('subject'))
$err[]='You have not selected a subject!';
if(!checkLen('message'))
$err[]='The message field is too short or empty!';
if((int)$_POST['captcha'] != $_SESSION['expected'])
$err[]='Wrong security code!';
if(count($err))
{
$_SESSION['errStr'] = implode('<br />',$err);
header('Location: '.$_SERVER['HTTP_REFERER']);
exit();
}
//submission data
$IP=$_SERVER['REMOTE_ADDR'];
$name=$_POST['name'];
$email=$_POST['email'];
$date=(gmdate(" Y/m/d "));
$time = date('H:i:s');
$message=$_POST['message'];
$from="noreply#tutorialpot.com";
$subject = " from ".$_POST['name']." | contact form";
$headers = "From: ".$from."\r\n";
$headers .= "Reply-to: ".$from."\r\n";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//checks whether send to my email address is set
if ($cc == 1) {
$headers .= 'Cc:'. $_POST['email']."\r\n";
}
$msg =
"<p><strong>Name: </strong>" .$name. "</p>
<p><strong>Email Address: </strong>" .$email. "</p>
<p><strong>Enquiry: </strong>" .$_POST['subject']. "</p>
<p><strong>Message: </strong>" .$message. "</p>
<br/> <br/>
<p>This message was sent from the IP Address:" .$ipaddress." on".$date. "at".$time."</p>";
if(#mail($email, $subject, $msg, $headers))
{
$success=array();
$success[]='Your message has been sent! | Thank you';
$_SESSION['sent'] = implode('<br />',$success);
header('Location: '.$_SERVER['HTTP_REFERER']);
exit();
}
else{
$err[]='your message could not be sent due to a network problem please try again.!';
$_SESSION['errStr'] = implode('<br />',$err);
header('Location: '.$_SERVER['HTTP_REFERER']);
exit();
}
}
?>
<div class="fieldContainer">
<label for="name" >*Name: </label>
<input class="validate[required,minSize[3]] input1" id="name" name="name" type="text" autofocus="autofocus" placeholder="NAME"/><br /><br />
<label for="email">*Email</label>
<input class="validate[required,custom[email]] input1" id="email" name="email" type="text" placeholder="EMAIL" /><br /><br />
<label for="subect" >*Subject</label>
<select id="dropdown4" name="subject" class="validate[required] input1">
<option selected="selected" value="">--Choose--</option>
<option value="Quote">Quote</option>
<option value="Suggestion">Suggestion</option>
<option value="Question">Question</option>
<option value="Business Proposal">Business Proposal </option>
<option value="Advertising">Advertising</option>
<option value="Complaint">Complaint</option>
<option value="Other">Other</option>
</select><br /><br />
<label for="message" >*Message</label>
<textarea rows="10" cols="15" name="message" class="validate[required,minSize[3],maxSize[300]] input1" id="message" placeholder=" MESSAGE CONTENTS"></textarea><br /><br />
<legend>*Human Verification (HELP US FIGHT SPAM)</legend>
<label for="captcha">25+9=</label>
<input type="text" class="validate[required,custom[integer]] input1 " name="captcha" id="captcha" maxlength="2" placeholder="DO A LITTLE MATH" />
<p>
<input type='checkbox' id='cc' name='cc' value='1' />
Send a copy to your email address
</p>
</div>
<div class="signupButton">
<input name="send" type="submit" class="btnsubmit" id="btnsubmit" />
<!--<input class="blackb" type="submit" name="send" id="submit"/>-->
</div>
</form>
This tutorial seems to have a few mistakes (at least at a first glance).
It uses $cc however this variable is not defined anywhere.
It sends the message to $email, but $email = $_POST['email'] (line 42) so it sends that e-mail to the e-mail address provided in the form (?). You want to fix line 62 with:
if(#mail('yourem#il.com', $subject, $msg, $headers))
It is also not sanitising the inputs so you can inject headers into the e-mail message. More explained here.
Finally, if the CC functionality was properly implemented (i.e. $cc was defined), you would send a copy of the e-mail to the sender (CC) thus revealing your e-mail address (not good if you want to avoid spam). You should send a separate e-mail to the sender.
It is this section that sends the message as mail returns bool. The first paramters is the to address (see link)
if(#mail($email, $subject, $msg, $headers))
http://php.net/manual/en/function.mail.php
In the example the email will go to the address the user enters as seen as $email is populated with the posted value
$email=$_POST['email'];
but you can hardcode to what ever you want.
if(#mail('youremail#domain.com', $subject, $msg, $headers))

Contact form Not Working Keeps Giving Me Array

So I have this contact script which works great in firefox but whenever anyone tries it in ie 7 or 8 the plan always returns array and for the life of me I cant figure out what I did wrong. Any help would be greatly appreciated.
<?php
if(!$_POST) exit;
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$cname = $_POST['cname'];
$address1 = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$plan = $_POST['plan'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($cname) == '') {
echo '<div class="error_message">Attention! Please enter your Company Name.</div>';
exit();
}
if(trim($address1) == '') {
echo '<div class="error_message">Attention! Please enter your Address.</div>';
exit();
}
if(trim($city) == '') {
echo '<div class="error_message">Attention! Please enter your city.</div>';
exit();
}
if(trim($state) == '') {
echo '<div class="error_message">Attention! Please enter your state.</div>';
exit();
}
if(trim($zip) == '') {
echo '<div class="error_message">Attention! Please enter your zip code.</div>';
exit();
}
else if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "email#email.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Veterans Career Fair: You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name from $cname, they wish to sign up for the $plan Plan. Their additional information is as follows:\r\n\n";
$e_reply = "Contact $name via email, $email or via phone $phone. \r\n\n";
$e_mail = "Address of $name is: $address1 $address2, $city, $state $zip";
$msg = $e_body . $e_reply . $e_mail;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "<p>You should hear from us in 48 hours</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
}
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
The Html
<form method="post" action="bin/sendme.php" name="contactform" id="contactform">
<label>Full Name</label>
<input name="name" type="text" id="name" size="30" value="" /><br />
<label>Email</label>
<input name="email" type="text" id="email" size="30" value="" /><br />
<label>Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" /><br />
<label>Company Name</label>
<input name="cname" type="text" id="cname" size="30" value="" /><br />
<label>Address 1</label>
<input name="address" type="text" id="address" size="30" value="" /><br />
<label>Address 2</label>
<input name="address2" type="text" id="address2" size="30" value="" /><br />
<label>City</label>
<input name="city" type="text" id="city" size="30" value="" /><br />
<label>State</label>
<input name="state" type="text" id="state" size="30" value="" /><br />
<label>Zip Code</label>
<input name="zip" type="text" id="zip" size="30" value="" /><br />
<label>Plan</label>
<select name="plan" type="text" id="plan">
<option value="Platinum">Platinum Sponsorship</option>
<option value="Gold">Gold Sponsorship</option>
<option value="Silver">Silver Sponsorship</option>
<option value="Survey">Survey Sponsorship</option>
<option value="Marquee">Marquee Sponsorship</option>
</select>
<label>3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="REGISTER NOW" />
</form>
The Jquery
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(750,function() {
$('#message').hide();
$('#submit')
.after('<img src="assets/ajax-loader.gif" class="loader" />')
.attr('disabled','disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#phone').val(),
cname: $('#cname').val(),
address: $('#address').val(),
city: $('#city').val(),
state: $('#state').val(),
zip: $('#zip').val(),
plan: $('#plan').val(),
verify: $('#verify').val()
},
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
$('#contactform #submit').attr('disabled','');
if(data.match('success') != null) $('#contactform').slideUp('slow');
}
);
});
return false;
});
<select name="plan" type="text" id="plan">
should be
<select name="plan" id="plan">
The html select element does not have an attribute type so perhaps that's confusing IE

Categories