Jam*_*son 4 html php email wordpress
我在使用 wp_mail 函数时遇到问题,希望有人可以帮助我。
我需要在用户添加到文本区域“消息”的电子邮件中插入换行符。
有人可以帮忙吗?
我目前有以下代码从联系表单发送电子邮件:
<?php
if( !isset($_REQUEST) ) return;
require('../../../../wp-load.php');
function wpse27856_set_content_type(){
return "text/html";
}
add_filter( 'wp_mail_content_type','wpse27856_set_content_type' );
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$msg = $_REQUEST['message'];
$headers = 'From: '.$name.' <'.$email.'>' . "\r\n";
$message = '
<html>
<body>
Someone has made an enquiry on the online contact form:
<br /><br />
<b>Contact Details:</b><br />
'.$name.'<br />
'.$phone.'<br />
'.$email.'<br /><br />
<b>Message:</b><br />
'.$msg.'<br />
<br /><br />
</body>
</html>
';
wp_mail('email@email.co.uk', 'Contact form Message' , $message, $headers);
?>
Run Code Online (Sandbox Code Playgroud)
默认情况下,wp_mail() 以纯文本形式发送消息,因此电子邮件客户端不会解析 HTML。
在您的电子邮件中包含以下标头:
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Run Code Online (Sandbox Code Playgroud)
由于您的电子邮件采用 HTML 格式,因此最好使用正确的 HTML 样板(HTML、HEAD、BODY...)使其有效。
或者,您可以
通过回车符 (\r\n) 替换标签,但您仍然需要删除标签。
mail() 的 PHP 文档已经介绍了这一点,wp_mail() 围绕该文档进行包装。
http://php.net/manual/en/function.mail.php