如何通过在邮件内容中插入html来使用php发送邮件?
我尝试在内部插入html代码$message
,当我测试时显示错误
像这样Parse error: syntax error, unexpected 'margin' (T_STRING)
我能怎么做 ?
<?PHP
include("connect.php");
$email = "[email protected] /cdn-cgi/l/email-protection";
$to = $email;
$subject = "test subject";
$message = "
<body style="margin: 0; padding: 0;">
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<img src="https://i.stack.imgur.com/Jy9QUm.jpg"/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <[email protected] /cdn-cgi/l/email-protection>' . "\r\n";
$headers .= 'Return-Path: [email protected] /cdn-cgi/l/email-protection' . "\r\n";
mail($to, $subject, $message, $headers, '[email protected] /cdn-cgi/l/email-protection');
?>
您在包装时遇到问题$body
字符串试试这个
<?PHP
include("connect.php");
$email = "[email protected] /cdn-cgi/l/email-protection";
$to = $email;
$subject = "test subject";
$message = "
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='https://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <[email protected] /cdn-cgi/l/email-protection>' . "\r\n";
$headers .= 'Return-Path: [email protected] /cdn-cgi/l/email-protection' . "\r\n";
mail($to, $subject, $message, $headers, '[email protected] /cdn-cgi/l/email-protection');
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)