rvdb86 Posted June 16, 2009 Share Posted June 16, 2009 hey guys hope some one can help me out. I am submitting a form through ajax. The file sendform.php processes the data sent and sends it as an email. The problem is that the user enters their email address in to the email field on the form, which is used as the sender value in the email, but for some reason $_POST['email'] is blank. ??? This is the AJAX part that send the form data to sendform.php: makePOSTRequest('Scripts/sendform.php', poststr); Any ideas would be really appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/ Share on other sites More sharing options...
KevinM1 Posted June 16, 2009 Share Posted June 16, 2009 One line of code isn't enough to diagnose the problem. Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857083 Share on other sites More sharing options...
rvdb86 Posted June 16, 2009 Author Share Posted June 16, 2009 Sorry, This is the javascript: var http_request = false; function makePOSTRequest(url, parameters) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type //http_request.overrideMimeType('text/xml'); http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('POST', url, true); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.setRequestHeader("Content-length", parameters.length); http_request.setRequestHeader("Connection", "close"); http_request.send(parameters); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { //alert(http_request.responseText); result = http_request.responseText; document.getElementById('contact-cube').innerHTML = result; } else { alert('There was a problem with the request.'); } } } function get(obj) { var poststr = "Name=" + escape(encodeURI(document.getElementById("name").value )) +"&Telephone=" + escape(encodeURI( document.getElementById("telephone").value )) +"&Email=" + escape(encodeURI( document.getElementById("email").value )); makePOSTRequest('Scripts/sendform.php', poststr); } And this is the sendform.php: require_once "Mail.php"; $from = $_POST['name'] . " <".$_POST['email'].">"; $to = "Me <me@mel>"; $subject = "Subject"; $body = "Hi,\n\nHow are you?"; $host = "mail.host.co.il"; $username = "Usernamel"; $password = "Password"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857085 Share on other sites More sharing options...
KevinM1 Posted June 16, 2009 Share Posted June 16, 2009 Hmm...where is poststr being set? Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857095 Share on other sites More sharing options...
rvdb86 Posted June 16, 2009 Author Share Posted June 16, 2009 Hmm...where is poststr being set? to sendform.php Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857099 Share on other sites More sharing options...
KevinM1 Posted June 16, 2009 Share Posted June 16, 2009 Hmm...where is poststr being set? to sendform.php Set, not sent . Where/how is the poststr variable actually being assigned to? Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857102 Share on other sites More sharing options...
rvdb86 Posted June 16, 2009 Author Share Posted June 16, 2009 Sorry miss read... here is the code that sets postr: var poststr = "Name=" + escape(encodeURI(document.getElementById("name").value )) +"&Telephone=" + escape(encodeURI( document.getElementById("telephone").value )) +"&Email=" + escape(encodeURI( document.getElementById("email").value )); Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857104 Share on other sites More sharing options...
KevinM1 Posted June 16, 2009 Share Posted June 16, 2009 Have you tried changing the sendmail.php code to: $_POST['Email'] ?? I ask, because the name component of the name-value pairs you send via the poststr variable all have their first letters as uppercase. Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857108 Share on other sites More sharing options...
rvdb86 Posted June 16, 2009 Author Share Posted June 16, 2009 Nightslyr Thank you soo much! was a silly overlook on my case.. I guess I have been staring at the screen for to long! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857111 Share on other sites More sharing options...
KevinM1 Posted June 16, 2009 Share Posted June 16, 2009 Nightslyr Thank you soo much! was a silly overlook on my case.. I guess I have been staring at the screen for to long! Thanks! Hehe, no problem. I've done the same thing many times myself. Quote Link to comment https://forums.phpfreaks.com/topic/162383-solved-php-and-ajax-post-request/#findComment-857118 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.