PHP mail not sending form data with ajax. Data is blank in email -
i'm working on simple signup form in codeignitor install.
the email getting sent, form data isn't showing in email message. data sent via ajax welcome file , hits public function signup().
it's hitting file, since email getting delivered, no form data.
form:
<div class="form"> <form onsubmit="return checkrequired(this)" method="post" id="subform"> <div class="signupbox"> <span class="label"><label for="firstname">first name:</label></span> <span><input type="text" name="firstname" id="firstname" size="25" class="required" /></span> </div> <div class="signupbox"> <span class="label"><label for="lastname">last name:</label></span> <span><input type="text" name="lastname" id="lastname" size="25" class="required" /></span> </div> <div class="signupbox"> <span class="label"><label for="email">email:</label></span> <span><input type="text" name="email" id="email" size="25" class="required" /></span> </div> <div class="signupbox"> <span class="label"><label for="company">company:</label></span> <span><input type="text" name="company" id="company" size="25" /></span> </div> <div class="signupbox"> <span class="label"><label for="comments">tell yourself:</label></span> <span><textarea name="comments" id="comments" cols="45" rows="5" ></textarea></span> </div> <div> <span class="button"><input type="submit" value="sign up" id="ajaxsubmit" /></span> </div> </form> </div>
signup.js:
$(document).ready(function(){ $('#ajaxsubmit').click(function(){ var formobj = new object(); formobj.firstname = $('#firstname').val(); formobj.lastname = $('#lastname').val(); formobj.email = $('#email').val(); formobj.company = $('#company').val(); formobj.comments = $('#comments').val(); //alert(json.stringify(formobj)); $.ajax({ type: 'post', url: 'http://www.alloi.co/signup', datatype: 'json', data: json.stringify(formobj) }); }) });
welcome.php:
public function signup() { $fname = $this->input->post('firstname', true); $lname = $this->input->post('lastname', true); $email = $this->input->post('email', true); $company = $this->input->post('company', true); $comments = $this->input->post('comments', true); $headers = "mime-version: 1.0"; $headers = "content-type: text/plain; charset=iso-8859-1"; $headers = "x-mailer: php/".phpversion(); $message = $fname." ".$lname. " has signed company.\n\nyou can reach ".$fname." @ ".$email."\n\n".$fname." works ".$company. "\n\n \n\n" .$comments; mail("someone@email.com", 'alloi account sign-up', $message, $headers); }
email message:
has signed alloi.
you can reach @
works for
i'm sure it's simple, i'm still learning. doing wrong not send form data?
thank in advance,
steven
you sending json in post try read data application/x-www-form-urlencoded on server side, if want read data on server side pass formobj
is
$.ajax({ type: 'post', url: 'http://www.alloi.co/signup', data: formobj });
Comments
Post a Comment