jquery - Asynchronously Send HTML Email with PHP After Form Submit -


i'm trying make form submits fields asynchronously database , send out html conformation email submitted email address. db part working fine can't send out html email (but none html email works, see more info below).

here's jquery , php i'm using:

jquery (this function gets called on click):

function commentfio() {     var name = $('.fio #name_js').val();     var name = encodeuricomponent(name);      var email = $('.fio #email_js').val();     var email = encodeuricomponent(email);      var telephone = $('.fio #telephone_js').val();     var telephone = encodeuricomponent(telephone);      var hkid = $('.fio #hkid_js').val();     var hkid = encodeuricomponent(hkid);      var comment = $('.fio #comment_js').val();     var comment = encodeuricomponent(comment);      if($('.fio #marketing').prop('checked')) {         var marketing = '1';     }      else {         var marketing = '0';     }     if($('.fio #term').prop('checked')) {         var term = '1';     }      else {         var term = '0';     }     var ajaxurl = '<?php echo $campaign_root_directory; ?>/ajax.php?dir=<?php echo $campaign_root_directory; ?>&task=submit_comment&youtuber=fio&name=' + name + '&email=' + email + '&telephone=' + telephone + '&hkid=' + hkid + '&comment=' + comment + '&marketing=' + marketing + '&term=' + term;      $('.video_overlay_wrap .content_wrap').scrolltop(0);     $(".video_overlay_wrap .fio .vote.block").html(load_gif);     $(".video_overlay_wrap .fio .vote.block").load(ajaxurl, function() {         $(".video_overlay_wrap .fio .comment.block").html(load_gif);         $(".video_overlay_wrap .fio .comment.block").load("<?php echo $campaign_root_directory; ?>/ajax.php?dir=<?php echo $campaign_root_directory; ?>&task=fetch_comment&youtuber=fio");     }); } 

php (detects task variable in url):

            // localize , sanitize             $youtuber = strip_tags(mysql_real_escape_string($_get['youtuber']));             $name = strip_tags(mysql_real_escape_string($_get['name']));             $email = strip_tags(mysql_real_escape_string($_get['email']));             $telephone = preg_replace('/\d/', '', strip_tags(mysql_real_escape_string($_get['telephone'])));             $hkid = strip_tags(mysql_real_escape_string($_get['hkid']));             $comment = strip_tags(mysql_real_escape_string($_get['comment']));             $marketing = strip_tags(mysql_real_escape_string($_get['marketing']));             $term = strip_tags(mysql_real_escape_string($_get['term']));              // clear default             if($name==$field_name) {                 $name = '';             }             elseif($email==$field_email) {                 $email = '';             }             elseif($telephone==$field_telephone) {                 $telephone = '';             }             elseif($hkid==$field_hkid) {                 $hkid = '';             }             elseif($comment==$field_comment) {                 $comment = '';             }              // set check box value             if($marketing==1) {                 $marketing = 'i agree receive promotional material.';             }             else {                 $marketing = '';             }             if($term==1) {                 $term = 'i have read , agree terms , privacy policy.';             }             else {                 $term = '';             }              // validate fields             if($youtuber!='' && $name!='' && $email!='' && filter_var($email, filter_validate_email) && $telephone!='' && is_numeric ($telephone) && $hkid!='' && strlen($hkid)<=10 && strlen($hkid)>=7 && $comment!='' && $term!='') {                 $insert = mysql_query("                     insert                          comment_index (                             last_update,                             cookie_id,                             youtuber,                             name,                             email,                             telephone,                             hkid,                             comment,                             marketing,                             term,                             ip,                             user_agent                         )                     values (                         '$current_time',                         '$cookie_id',                         '$youtuber',                         '$name',                         '$email',                         '$telephone',                         '$hkid',                         '$comment',                         '$marketing',                         '$term',                         '$ip',                         '$user_agent'                     )                 ");                 if($insert) {                      // set email content                     $recipient = $email;                     $subject = "subject";                     $message = '                         first line.<br>                         second line.                     ';                      // send email                     $sender = 'sender name <info@email.com>';                     $headers = "from:" . $sender . "\r\n";                     $headers .= 'content-type: text/html' . "\r\n";                      $mail_result = mail($recipient,$subject,$message,$headers);                      if($mail_result) {                         $output = 'success!';                     }                     else {                         $output = 'fail...';                     }                 }                 else {                     $output = 'error';                 } 

i think problem $headers .= 'content-type: text/html' . "\r\n"; because if remove line, email gets sent not in html format.

can please help? in advance!

edit: little more info, tried adding charset mail header before did not work. if try use same code send mail not asynchronously, works. i'm wondering if have async.

replace last append operation on headers this:

$headers .= "content-type: text/html; charset=iso-8859-1\r\n";

you not specifying charset. read this understand why needed.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -