dream25 Posted July 11, 2007 Share Posted July 11, 2007 Hi..All.. I have a code for contact us page in php with ajax, i have a problem when i run the code, actually the process is... sending a confirmation mail to who has contact me, i recieved a mail who has send to me.. but the confirmation mail has not send to him.. so whats the problem in it.. below i attached the code..Thanks in advance.. <? if(!isset($rnd) || !isset($name) || !isset($email) || !isset($subject) || !isset($body)) { showform(); } else { processform(); } function processform(){ echo "Checking"; global $name, $email, $subject, $body; $email_to1 = "shree_uday@yahoo.com"; // enter your email here $email_from1 = $mail; $email_to2 = $mail; $email_from2 = $email_to1; $email_subject = "Contact Form: ".stripslashes($subject); $email_message = "Please find below a message submitted by '".stripslashes($name); $email_message .="' on ".date("d/m/Y")." at ".date("H:i")."nn"; $email_message .="--------- START OF SUBMITTED MESSAGE ---------nn"; $email_message .= stripslashes($body); $email_message .="nn--------- END OF SUBMITTED MESSAGE ---------nn"; $confirmation_subject = "Thank you for your message"; $confirmation = "This is to confirm we have received your message...."; // SEND EMAIL TO email_to2 - confirmation $headers = 'From: '.$email_from2."rn" . 'Reply-To: '.$email_from2."rn" . 'X-Mailer: PHP/' . phpversion(); mail($email_to2, $email_subject, $confirmation, $headers); // SEND EMAIL TO email_to1 - message to you!! $headers = 'From: '.$email_from1."rn" . 'Reply-To: '.$email_from1."rn" . 'X-Mailer: PHP/' . phpversion(); mail($email_to1, $email_subject, $email_message, $headers); mail($email, $subject, $message, "From: $email"); echo "Thank You."; die(); } // end processform() function showform() { ?> <STYLE type="text/css"> div.row { clear:both; } div.row span.label { float: left; width: 60px; text-align: right; } div.row span.formw { float: right; width: 220px; text-align: left; } div.row span.left { float: left; text-align: left; font-weight: bold; color: #fff; width: 49%; } div.row span.right { float: right; text-align: right; font-weight: bold; color: #fff; width: 49%; } div.row span.submit{ width:280px; text-align:center; } #form{ width: 300px; background-color: #f6f6f6; border: 1px dotted #666; padding: 2px; margin: 0px auto; } #confirmation{ width: 300px; height:220px; background-color: #f6f6f6; border: 1px dotted #666; padding: 2px; margin: 0px auto; text-align: center; font-weight: bold; } </STYLE> <script type="text/javascript"> <!-- var http = createRequestObject(); var areal = Math.random() + ""; var real = areal.substring(2,6); function createRequestObject() { var xmlhttp; try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} catch(f) { xmlhttp=null; } } if(!xmlhttp&&typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } return xmlhttp; } function sendRequest() { var rnd = Math.random(); var name = escape(document.getElementById("name").value); var email = escape(document.getElementById("email").value); var subject = escape(document.getElementById("subject").value); var body = escape(document.getElementById("body").value); try{ http.open('POST', 'ajax_contact.php'); http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http.onreadystatechange = handleResponse; http.send('name='+name+'&email='+email+'&subject='+subject+'&body='+body+'&rnd='+rnd); } catch(e){} finally{} } function check_values() { var valid = document.getElementById("valid").value; if(real !== valid) { alert("Ant-Bot check failed.....nPlease enter the 4 digits as they appear."); return false; } var name = document.getElementById("name").value; var email = document.getElementById("email").value; var subject = document.getElementById("subject").value; var body = document.getElementById("body").value; if(trim(name) == "" || trim(email) == "" || trim(subject) == "" || trim(body) == "") { alert("Please complete all fields"); } else { if(isEmail(email)) { document.getElementById("submit").disabled=true; document.getElementById("submit").value='Please Wait..'; sendRequest(); } else { alert("Email appears to be invalid.nPlease check."); document.getElementById("email").focus(); document.getElementById("email").select(); } } } function handleResponse() { try{ if((http.readyState == 4)&&(http.status == 200)){ var response = http.responseText; document.getElementById("confirmation").innerHTML = response; document.getElementById("confirmation").style.display =""; document.getElementById("form").style.display = "none"; } } catch(e){} finally{} } function isUndefined(a) { return typeof a == 'undefined'; } function trim(a) { return a.replace(/^s*(S*(s+S+)*)s*$/, "$1"); } function isEmail(a) { return (a.indexOf(".") > 0) && (a.indexOf("@") > 0); } function botCheckInfo() { alert("To prevent automatic programs (bots)nfrom submitting spam through this form,nwe have added a simple validationncheck to the form. You must enter nthese 4 digits in the box provided innorder to submit the form."); } // --> </script> <? } // end showform() ?> <div id="form"> <form> <div class="row"><span class="label">Name:</span> <span class="formw"><input type="text" id="name" size="30" /></span></div> <div class="row"><span class="label">Email:</span> <span class="formw"><input type="text" id="email" size="30" /></span></div> <div class="row"><span class="label">Subject:</span> <span class="formw"><input type="text" id="subject" size="30" /></span></div> <div class="row"><span class="label">Message:</span> <span class="formw"><textarea cols="23" rows="6" id="body"></textarea></span></div> <div class="row" align="center"><a href="javascript:botCheckInfo()">Anti-bot check</a>. Enter Digits '<b><script language="javascript">document.write(real)</script></b>' below:</div> <div class="row" align="center"><input type="text" id="valid" size="15" /></div> <div class="row" align="center"> </div> <div class="row" align="center"> <input type="button" value="Submit" id="submit" onClick="return check_values();"></div> </form> </div> <div id="confirmation" style="display:none"></span> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 Please use [code] and [/code] tags! You've got new lines and styles activating! Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 11, 2007 Author Share Posted July 11, 2007 thanks... now u check the code.. plz let me out Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 Which one is failing - to1 or to2? Quite note: It'd be a good idea to get into the habit of using <?php instead of <? as short tags might not always be enabled on another server. Saves you having to edit everything should circumstances change. Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 11, 2007 Author Share Posted July 11, 2007 to2 is failing Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 It can't be a header problem because the other email is sending OK (as you say) and they're both using the same. I see you're pulling the email from a global $email - I'd echo that to the browser and see what it contains as I suspect that's where the problem lies. Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 11, 2007 Author Share Posted July 11, 2007 Yes.. i checked the processform function with echo statement.. its working.. onething.. i recieved a mail from the user..in that.. to,subject,message only displayed, but the from column has shown nothing.. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 I just spotted this: $headers = 'From: '.$email_from2."rn" . Shouldn't that be "\r\n"? Might be worth dumping all the variables and see exactly what they all contain as there's somethign wrong with one of them unless the recipient's ISP is dumping them? I've had this happen to me while testing. They thought I was spamming. Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 11, 2007 Author Share Posted July 11, 2007 Thanks.. its working.. better i give the url..u check whether is it right or not.. www.venkidesigns.com/udaya/ajax_contact.php Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 I got the email OK but no message. I typed: A test for slash's and "quotes" If you want a capcha script - I've got one you can have Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 Just tried sending one without a slash and quotes and nothign has come through... Just tried a third time and still nothing! Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 11, 2007 Author Share Posted July 11, 2007 but i didnt recieve any mail from u.. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 Strange! I've no idea what's going on. Not sure if you're aware but mail() returns a boolean value either true or false. Might be worth adding it into an if() statement to check if its failing internally or elsewhere. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 Just noticed this in the first email: The sender of this message, yesideez@hotmail.co.uk, could not be verified by Sender ID. Learn more about Sender ID. When sending a mail you can use this format as "from" $from='From: Yesideez <some@thing.com>'; I can see you're just specifying the email address on its own. Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 11, 2007 Author Share Posted July 11, 2007 now i send a mail to my id by ur id..if u recieve any mail..plz inform to me.. and also plz tell what content u recive Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 If you used the email address I posted in that example I won't get anything as I made that up. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 I had two come through with "Mail Checker" as the subject string but nothign in either body contents. Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 11, 2007 Author Share Posted July 11, 2007 thanks.. really im getting aware of this.. i dont know whats happening in that... Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 All in all I've sent 4 emails using my hotmail email and just to be safe I sent 2 using my private email. I only had 1 hotmail email come through. I have to pop out now and pic up some photos - back in about 30 mins... EDIT: Just had only the second come through on my private email but again no body text! Quote Link to comment Share on other sites More sharing options...
dream25 Posted July 12, 2007 Author Share Posted July 12, 2007 hi.. did u get any idea about my post Quote Link to comment 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.