dpwo36915 2016-02-23 09:38
浏览 68
已采纳

设置标题后无法在电子邮件中发送链接

I am not able send links in email.
I am using wp_mail() function to send email.
When i set header $headers .= "Content-Type: text/html; "; this header removes href attribute in received email.

i am using wp_editor for textarea. I also tried html textarea but the result was same.

When i send mail without setting header, i am getting anchor tag as text.
<a href=\'http://example.com\'>Example</a>

here is my 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 this is php code

add_action('wp_ajax_mail_link_popup','mail_link_popup');
function mail_link_popup()
{
//  $headers .= "MIME-Version: 1.0
";

    $headers .= "Content-Type: text/html; 
";
    wp_mail($_REQUEST['to_email'],$_REQUEST['subject'],$_REQUEST['message_test'],$headers);
}  

Here is 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>
  • 写回答

2条回答 默认 最新

  • douci1615 2016-02-23 12:20
    关注

    Nothing is wrong with the code. I just added message body in stripslashes()

    add_action('wp_ajax_mail_link_popup','mail_link_popup');
    function mail_link_popup()
    {
        $headers = 'Content-type: text/html;charset=utf-8';
        wp_mail($_REQUEST['to_email'],$_REQUEST['subject'],stripslashes($_REQUEST['message_test']),$headers);
    
    }
    

    And it's working now

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私