wordpress - Php mail script - not including form values in sent email -


i have php mail script gets triggered following.

var theform = document.getelementbyid( 'mailinglist-form' );  new stepsform( theform, {     onsubmit : function( form ) {     var messageel = $('.final-message');         // hide form         $('.simform-inner').addclass('hide' );         //remove cursor         $('#q2').blur();         //get input field values data sent server         post_data = {             'user_name'     : $('input[name=name]').val(),              'user_email'    : $('input[name=email]').val()         };          //ajax post data server  $.post('mail.php', post_data, function(response){           if(response.type == 'error'){          //load json data server , output message              messageel.html('sorry, please try again later.');         $(messageel).addclass( 'show' );             }else{         messageel.html(response.text);         $(messageel).addclass( 'show' );         }          }, 'json');     }  } ); 

this calls following mail.php file

<?php if($_post) { $to_email = "myemail@gmail.com"; //recipient email $subject = "mailing list request"; $from = 'anotheremail@gmail.com';     //check if ajax request, exit if not if(!isset($_server['http_x_requested_with']) , strtolower($_server['http_x_requested_with']) != 'xmlhttprequest') {      $output = json_encode(array( //create json data         'type'=>'error',          'text' => 'sorry request must ajax post'     ));     die($output); //exit script outputting json data }   //sanitize input data using php filter_var(). $user_name      = filter_var($_post["user_name"], filter_sanitize_string); $user_email     = filter_var($_post["user_email"], filter_sanitize_email);  //additional php validation if(strlen($user_name)<3){ // if length less 3 output json error.     $output = json_encode(array('type'=>'error', 'text' => 'name short or empty!'));     die($output); } if(!filter_var($user_email, filter_validate_email)){ //email validation     $output = json_encode(array('type'=>'error', 'text' => 'please enter valid email!'));     die($output); } //email body $message_body = $message."".$user_name." wants sign mailing list. details below:\r\n\nname : ".$user_name."\r\nemail : ".$user_email."\r\n";  //proceed php email. $headers = 'from: '.$from.'' . "\r\n" . 'reply-to: '.$from.'' . "\r\n" . 'x-mailer: php/' . phpversion();  $send_mail = mail($to_email, $subject, $message_body, $headers);  if(!$send_mail) {     //if mail couldn't sent output error. check php email configuration (if ever happens)     $output = json_encode(array('type'=>'error', 'text' => 'sorry, please try again later.'));     die($output); }else{     $output = json_encode(array('type'=>'message', 'text' => 'all done. signing up.'));     die($output); } } ?> 

now seems work, sends email users name , email address said email "myemail" "anotheremail".

whats weird sometime there no user name or email address the rest of message.

can tell me whats going on here, i've hit road block on one.

thanks , sorry poorly formatted code... :p

i'm surprised doesn't flat out not work.

$from = 'anotheremail@gmail.com' <- not have ; @ end... have thought php engine take exception this.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -