php - Not able to send links in email after setting header -


i not able send links in email.
using wp_mail() function send email.
when set header $headers .= "content-type: text/html; \r\n"; header removes href attribute in received email.

i using wp_editor textarea. tried html textarea result same.

when send mail without setting header, getting anchor tag text.
<a href=\'http://example.com\'>example</a>

here code.

jquery('.for_email').click(function(e){         e.preventdefault();         var mail_data = jquery('.email_popup_form').serialize();         //console.log(mail_data);         jquery.ajax({             url:"<?php echo admin_url('admin-ajax.php'); ?>",             data:'action=mail_link_popup&'+mail_data,             success:function(res)             {                 //console.log(jquery('#mycustomeditor_afds_ifr').contents().find('#tinymce').html());             }         });     }); 

and php code

add_action('wp_ajax_mail_link_popup','mail_link_popup'); function mail_link_popup() { //  $headers .= "mime-version: 1.0\r\n";      $headers .= "content-type: text/html; \r\n";     wp_mail($_request['to_email'],$_request['subject'],$_request['message_test'],$headers); }   

here html form

 <div class="modal fade" id="email_link_mymodal" role="dialog">     <div class="modal-dialog modal-lg">        <!-- modal content-->       <div class="modal-content">         <div class="modal-header">           <button type="button" class="close" data-dismiss="modal">&times;</button>           <h3 class="modal-title">email</h3>         </div>         <div class="modal-body">           <div class='row'>               <div class='container'>               <div class='col-md-9'>                  <form class="form-horizontal email_popup_form" role="form">                    <div class="form-group">                     <label class="control-label col-sm-2" for="email">to:</label>                     <div class="col-sm-10">                       <input type="email" class="form-control to_email" id="email" name='to_email'>                     </div>                   </div>                    <div class="form-group">                     <label class="control-label col-sm-2" for="pwd">from:</label>                     <div class="col-sm-10">                        <input type="email" class="form-control send_email" id="pwd" name='send_email' >                     </div>                   </div>                    <div class="form-group">                      <label class="control-label col-sm-2" for="sub">subject:</label>                     <div class="col-sm-10">                        <input type="text" class="form-control subject" id="sub" name='subject'>                     </div>                   </div>                    <div class="form-group">                        <label class="control-label col-sm-2" for="sub"></label>                       <div class="col-sm-10">                            <?php                            $content = '<div class="cont_test"></div>';                             $editor_id = 'mycustomeditor_afds';                             $settings = array(                             'media_buttons'=>false,                             'textarea_name'=>'message_test' ,                             'editor_class'=>'add_link_test' ,                             'media_buttons' => false,                             'quicktags'     => true                             );                             //wp_editor( $content, $editor_id ,$settings);                            ?>                         <textarea class='cont_test' name='message_test'></textarea>                       </div>                   </div>                    <div class="form-group">                      <div class="col-sm-offset-2 col-sm-10">                       <button type="submit" class="btn btn-default for_email">send email</button>                     </div>                   </div>                 </form>               </div>               </div>           </div>         </div>         <div class="modal-footer">           <button type="button" class="btn btn-default" data-dismiss="modal">close</button>         </div>       </div>      </div> </div> 

thats not how content header works in wordpress. need set header through add_filter

add_filter( 'wp_mail_content_type', 'setheader' ); wp_mail( 'me@example.net', 'the subject', '<a href="http://some.com"></a>' ); remove_filter( 'wp_mail_content_type', 'setheader' );   function setheader(){     return 'text/html'; } 

p.s. not forget reset content types.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -