我无法在电子邮件中发送链接
我正在使用wp_mail()
发送电子邮件的功能
设置标题时$headers .= "Content-Type: text/html; \\r\\n";
此标题删除href
属性。
我正在为textarea使用wp\\U编辑器。我也尝试了html文本区域,但结果是一样的。
当我在不设置邮件标题的情况下发送邮件时,我得到的锚定标记为文本
<a href=\\\'http://example.com\\\'>Example</a>
这是我的密码。
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());
}
});
});
这是php代码
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);
}
这是HTML表单
<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">×</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>
最合适的回答,由SO网友:milan patel 整理而成
代码没有问题。我刚刚在中添加了消息正文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);
}
现在开始工作了