ceilingwalker Posted August 14, 2011 Share Posted August 14, 2011 I’ve been attempting to get an AJAX contact form to work, but I’m out of ideas and need the help of a guru. The code was created by a third-party, but I’m starting to think it’s not even valid. I’ve pasted all of the code below for your review, from HTML, to JS, to the PHP. Any suggestions on how to make my contact form work would be greatly appreciated. HTML CODE: <div class="contact_submit_form form_24" style="width:600px;"> <div class="quickly_elements_left"> <div class="quickly_elements_label"> <input type="text" name="name" class="input" value="Name *"> </div> <div class="quickly_elements_label"> <input type="text" name="email" class="input" value="Email *"> </div> <div class="quickly_elements_label"> <input type="text" name="telephone" class="input" value="Telephone"> </div> </div> <div class="quickly_elements_right"> <div class="quickly_elements_label"> <input type="text" name="subject" class="input" value="Subject *"> </div> <div class="quickly_elements_label"> <textarea class="textarea" name="message" style="width:90%; height:65px;">Message *</textarea> </div> </div> <div class="quickly_elements_label"> <div class="form_24 contact_submit alignright"><h6><span class="small_buttons"><span class="ocean_l small_left"><span class="ocean_r small_right">Send Message</span></span></span></h6></div> <div class="quickly_form_message alignright"> </div> </div> </div> JS /* contact form and comment for settings */ _form_name = "Name *"; _form_email = "Email *"; _form_tel = "Telephone"; _form_subject = "Subject *"; _form_message = "Message *"; _form_comment = "Message *"; _form_url = "Web Site"; _error_name = "Error, Please check <strong>your name</strong> "; _error_email = "Error, Please check <strong>your email</strong> "; _error_subject = "Error, Please check <strong>your subject</strong> "; _error_message = "Error, Please check <strong>your message</strong> "; _error_comment = "Error, Please check <strong>your comment</strong> "; _send_message = "Please wait, sending..."; _thanks_message = "Success! Thank you for contact."; PHP <?php /* Getting & Settings some variables */ $address = "emailaddess@test.com"; /* Change here, write your email adress */ /* If mail messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF (\n) by CRLF (\r\n) automatically (which leads to doubling C (\r) if CRLF (\r\n) is used).. also you can change field names from Translate Settings */ $email_set = "LF"; $name = $_REQUEST["name"]; $email = $_REQUEST["email"]; $tel = $_REQUEST["tel"]; $subject = $_REQUEST["subject"]; $content = $_REQUEST["message"]; $sender = mb_encode_mimeheader($name, "UTF-7", "Q") . " <" . $email . ">"; $subject_utf = mb_encode_mimeheader($subject,"UTF-8", "B", "\n"); function Sendmail($from, $to, $subject, $plain, $html = false, $charset = "iso-8859-1") { if($email_set == "CRLF"){ $lb = "\r\n"; }else if($email_set == "LF"){ $lb = "\n"; } if($html == false) { $headers = "From: ".$from.$lb; $headers .= "Reply-To: ".$from.$lb; $headers .= "MIME-Version: 1.0".$lb; $headers .= "X-Priority: 3".$lb; $headers .= "X-Mailer: RobustMail [1.0]".$lb; $headers .= "Content-type: text/html; charset=".$charset.$lb; $mail_sent = @mail($to, $subject, $plain, $headers); return $mail_sent; } $random_hash = md5(microtime()); $headers = "From: ".$from.$lb; $headers .= "Reply-To: ".$from.$lb; $headers .= "MIME-Version: 1.0".$lb; $headers .= "X-Priority: 3".$lb; $headers .= "X-Mailer: RobustMail [1.0]".$lb; $headers .= "Content-Type: multipart/alternative;".$lb."\tboundary=\"bo_".$random_hash."\""; ob_start(); ?> --bo_<?php echo $random_hash.$lb; ?> Content-Type: text/plain; charset = "<?php echo $charset; ?>" Content-Transfer-Encoding: 7bit <?php echo $plain; ?> --bo_<?php echo $random_hash.$lb; ?> Content-Type: text/html; charset = "<?php echo $charset; ?>" Content-Transfer-Encoding: 7bit <?php echo $html; ?> --bo_<?php echo $random_hash; ?>-- <?php $message = ob_get_clean(); $to = is_array($to) ? implode(", " , $to) : $to; $mail_sent = @mail($to, $subject, $message, $headers); return $mail_sent; } $mailBody = ""; $mailBody .= "You got an email from your website!<br /><br />"; $mailBody .= "Name : ". $name . "<br />"; $mailBody .= "Email : ". $email . "<br />"; $mailBody .= "Telephone : ". $tel . "<br />"; $mailBody .= "Subject : ". $subject . "<br />"; $mailBody .= "Message : ". $content . "<br />"; $send_mail = sendMail($sender, $address, $subject_utf, $mailBody, $html = false, $charset = "utf-8"); $thanks_message = "Success! Thank you for contact."; $error_message = "Mail Failed, Please try again!"; if( $send_mail ) { echo $thanks_message; } else { echo $error_message; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/ Share on other sites More sharing options...
DavidAM Posted August 14, 2011 Share Posted August 14, 2011 In order for people to help you, you need to tell us what is wrong. "Does not work" is not a a description of a problem. Tell us what it should do, and what it does do. That being said, I quickly scanned through the code and the following things jump out at me: [*]The form fields names are using "proper case" (i.e. Subject) but the PHP is looking for them using lower case (i.e. subject); [*]Remove the "@" symbol in the two calls to mail (it should NOT be @mail(...), it should be mail(...)) - the "@" hides any errors that occur, errors should be fixed not hidden; [*]Turn on error reporting in development so you can see the errors and fix them [*]There is no <FORM> tag in there; [*]There is no AJAX or even any JavaScript code to call AJAX in there For error reporting, put this at the top of the PHP file: <?php error_reporting(E_ALL); ini_set("display_errors",1); Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/#findComment-1257177 Share on other sites More sharing options...
ceilingwalker Posted August 14, 2011 Author Share Posted August 14, 2011 What should be happening is that when someone submits a completed contact form there should be a confirmation stating that it was processed correctly and then I should receive an email with the submitted information. The confirmation appears to work, but the email is never received. You can see it in action on a temporary website here www.notallgood.com. It sounds like from your quick assessment that the contact form in its current state is not functional, but rather impersonating a contact form. Would you recommend me using different code or do you think what I have is salvageable? Thank you, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/#findComment-1257274 Share on other sites More sharing options...
DavidAM Posted August 14, 2011 Share Posted August 14, 2011 I really don't know how to answer that question. It would depend on what you are comfortable with and what your level of expertise is. In your original post, you stated: I’ve pasted all of the code below But there is no <FORM> tag in the code. I do not see any way that the form is submitting to your PHP code without a FORM tag. So, I don't know if that is all of the code, or most of the code, or what. And, I really cannot say whether the code is salvageable or not. If your code is executing and saying it sent the email, and you do not receive the email, there are a few things to look at there: 1) the mail function simply submits the mail to the (local) mail server. If it hands it off OK the function returns true. So, you need to make sure you have a working mail system installed. 2) The email address supplied in the FROM header really needs to be an email address that belongs to the server sending the mail. Otherwise, the server sending the mail may think you are trying to send a forged email and refuse to SEND it. Also, the server receiving the mail may believe it is forged and refuse to deliver it. (or it might be in your junk mail folder). Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/#findComment-1257331 Share on other sites More sharing options...
ceilingwalker Posted August 14, 2011 Author Share Posted August 14, 2011 You are correct. There is no <form> tag so I think it’s the Java that is stating the form is submitting, but it never actually ever talks to the PHP. I think I might not have been given the best code. Do you recommend any easy to integrate contact form code that I could use? My goal is to have the code submit without needing to need to load a new page, but still have a confirmation that it went through. Thank you, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/#findComment-1257356 Share on other sites More sharing options...
ceilingwalker Posted August 14, 2011 Author Share Posted August 14, 2011 Good news. I created a new PHP file and put my form elements in-between <form> tags and I'm able to receive emails. Now all I need to figure out is how to have a "form submitted successfully" on the same page. Is this possible using the PHP echo or do I need to use JS? Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/#findComment-1257406 Share on other sites More sharing options...
ceilingwalker Posted August 14, 2011 Author Share Posted August 14, 2011 I was able to get everything to work. Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/#findComment-1257468 Share on other sites More sharing options...
mcculley1108 Posted October 18, 2011 Share Posted October 18, 2011 Could you post the code that worked please? I am having the same exact problem with what I believe is the same theme. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/244755-contact-form-from-hell-%E2%80%93-help-needed/#findComment-1280318 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.