BoltZ Posted November 22, 2008 Share Posted November 22, 2008 Sorry if this is php or ajax not sure but here I go I hve a contact form and I can get it to do everything I want but actually SEND the email to me Heres my form <div id="form" style="padding-left:10px;"> <form action="pform.php"> <div> <p class="c3"></p> <h2>Please fill out this contact form for EncodeCSS.com</h2> <br /> <div><p><label class="c4">Full Name:</label> <input type="text" id="name" size="30" style="margin-left:15px;" /></p> <p><label class="c4">Your Email:</label> <input type="text" id="email" size="30" style="margin-left:10px;" /></p> <p><label class="c4">Your Subject:</label> <input type="text" id="subject" size="30" /></p> <div><label class="c4">Your Message</label></div> <textarea class="c5" onblur="this.style.borderWidth='1px'; this.style.margin='1px'; this.style.borderColor='#0099cc';" onfocus=" this.rows='13'; this.style.borderWidth='2px'; this.style.margin='0px'; this.style.borderColor='#0099cc';" id="body" cols="70" rows="8" name="body"> </textarea> <br /><br /> <input type="button" value="Submit" id="submit" onclick="return check_values();" /></div> </div> </form> <br /> <br /> <div id="confirmation" style="display:none"></div> <br /> <br /></div> Heres my pform.php <?php error_reporting(0); include 'cform_config.php'; if(!isset($rnd) || !isset($name) || !isset($email) || !isset($subject) || !isset($body)) { echo $error_message; die(); } $email_from = $email; $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")."\n\n"; $email_message .= stripslashes($body); $headers = 'From: '.$email_from."\r\n" . 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); // mail($email_it_to, $email_subject, $email_message, $headers); echo "<b>$confirmation</b>"; die(); ?> Heres my config <?php error_reporting(0); // configuration $page_title = "Contact Us Form"; $email_it_to = "devwebsites@gmail.com"; $error_message = "Please complete the form first"; $confirmation = "Thank you, your message has been successfully sent."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/ Share on other sites More sharing options...
.josh Posted November 22, 2008 Share Posted November 22, 2008 posted data (through regular form submission or through ajax) are passed to the target script either by POST or GET method. Unless you have register globals set to ON (which you shouldn't, and if you do, turn them off), the data in your target script will take the form of $_POST['varnamehere'] or $_GET['varnamehere'], depending on what method you used (post or get). Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696222 Share on other sites More sharing options...
gevans Posted November 22, 2008 Share Posted November 22, 2008 <div id="form" style="padding-left:10px;" method="POST"> <form action="pform.php"> <div> <p class="c3"></p> <h2>Please fill out this contact form for EncodeCSS.com</h2> <br /> <div><p><label class="c4">Full Name:</label> <input name="name" type="text" id="name" size="30" style="margin-left:15px;" /></p> <p><label class="c4">Your Email:</label> <input name="email" type="text" id="email" size="30" style="margin-left:10px;" /></p> <p><label class="c4">Your Subject:</label> <input name="subject" type="text" id="subject" size="30" /></p> <div><label class="c4">Your Message</label></div> <textarea class="c5" onblur="this.style.borderWidth='1px'; this.style.margin='1px'; this.style.borderColor='#0099cc';" onfocus=" this.rows='13'; this.style.borderWidth='2px'; this.style.margin='0px'; this.style.borderColor='#0099cc';" id="body" cols="70" rows="8" name="body"> </textarea> <br /><br /> <input type="button" value="Submit" id="submit" onclick="return check_values();" /></div> </div> </form> <br /> <br /> <div id="confirmation" style="display:none"></div> <br /> <br /></div> changes to your html ^^^ <?php error_reporting(0); include 'cform_config.php'; if(!isset($POST['name']) || !isset($POST['email']) || !isset($POST['subject']) || !isset($POST['body'])) { echo $error_message; die(); } $email_from = $POST['email']; $email_subject = "Contact Form: ".stripslashes($POST['subject']); $email_message = "Please find below a message submitted by '".stripslashes($POST['name']); $email_message .="' on ".date("d/m/Y")." at ".date("H:i")." "; $email_message .= stripslashes($POST['body']); $headers = 'From: '.$email_from." " . 'Reply-To: '.$email_from." " . 'X-Mailer: PHP/' . phpversion(); $result = mail($email_it_to, $email_subject, $email_message, $headers); if($result) echo "<b>$confirmation</b>"; else echo "didn't sent"; die(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696224 Share on other sites More sharing options...
BoltZ Posted November 22, 2008 Author Share Posted November 22, 2008 I used your code and filled out all the forms and It gave me a message of please fill out all the forms. Hmm Maybe you changed some names. Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696226 Share on other sites More sharing options...
gevans Posted November 22, 2008 Share Posted November 22, 2008 Is this getting to the php page past your JavaScript validation? Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696227 Share on other sites More sharing options...
BoltZ Posted November 22, 2008 Author Share Posted November 22, 2008 I would assume no since its giving me an error when i click the button of "Please fill out the form first" Heres my js 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', 'pform.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 = ''; 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 =""; } } 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); } Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696230 Share on other sites More sharing options...
Philip Posted November 22, 2008 Share Posted November 22, 2008 <?php if(!isset($POST['name']) || !isset($POST['email']) || !isset($POST['subject']) || !isset($POST['body'])) ?> Should really be: <?php if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['body'])) ?> Isset is great for checking to make sure a variable was set, but will still return true in all of those cases. However empty will check to make sure something was actually filled. Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696232 Share on other sites More sharing options...
BoltZ Posted November 22, 2008 Author Share Posted November 22, 2008 Ok its emailing me now but I am getting this email message Please find below a message submitted by '' on 22/11/2008 at 10:24 but theres no name or message there ;[ Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696239 Share on other sites More sharing options...
Philip Posted November 22, 2008 Share Posted November 22, 2008 Oops, didn't see there were 2 more $POST's.... they must be $_POST['varname'], not $POST['varname'] Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696242 Share on other sites More sharing options...
.josh Posted November 22, 2008 Share Posted November 22, 2008 probably because you didn't change $POST to $_POST in the rest of your script. Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696244 Share on other sites More sharing options...
BoltZ Posted November 22, 2008 Author Share Posted November 22, 2008 Ok thanks guys it works now Quote Link to comment https://forums.phpfreaks.com/topic/133779-contact-form-not-emailing/#findComment-696248 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.