Hey guys.
I’m trying to write a PHP file that will take the data entered into a form on an html page and send it to an email address, with a nice, decent layout, and then display a new page once it is successful. Here’s what I have so far, but for some reason it just isn’t working.
<form id="contact_form" method="post" action="send_form_email.php" novalidate>
<div>
<label>Name:*</label>
<input type="text" id="name" name="name" tabindex="1">
</div>
<div>
<label>Email:*</label>
<span id="sprytextfield1">
<label>
<input type="text" name="validateEmail" id="validateEmail" tabindex="2"/>
</label>
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
<br/><br/>
<p class="center"><input type="submit" id="submit" value="Submit" tabindex="4">
<a href="send_form_email.php">Email Form</a>
<br/><br/>
<br />
</p>
</form>
<div id="textarea">
<label>Comments:*</label>
<span id="sprytextarea1">
<textarea id="comments2" name="comments2" form="contact_form" tabindex="3"></textarea><br/>
<span id="countsprytextarea1"> </span><br/><span class="textareaRequiredMsg">A value is required.</span><span class="textareaMinChar* disabled word ** disabled word ** disabled word *g">Minimum number of characters not met.</span><span class="textareaMaxChar* disabled word ** disabled word ** disabled word *g">Exceeded maximum number of characters.</span></span></div><!-- #textarea -->
</div><!--End forms-->
And here’s the PHP
[php]
<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "New Contact Form Submission"; $name = $_POST['name']; // required $email_from = $_POST['validateEmail']; // required $comments = $_POST['comments2']; // required $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($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); ?>//essentially, this should redirect to a new page.
<?php } ?>[/php]