【发布时间】:2016-02-04 17:27:04
【问题描述】:
如何通过将html插入邮件内容来使用php发送邮件?
我尝试在$message 内插入html 代码,当我测试时显示错误
喜欢这个Parse error: syntax error, unexpected 'margin' (T_STRING)
我该怎么办?
<?PHP
include("connect.php");
$email = "test_mail@hotmail.com";
$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="http://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 <noreply@example.com>' . "\r\n";
$headers .= 'Return-Path: return@example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn@example.com');
?>
【问题讨论】:
-
用单引号代替双引号将您的消息括起来
-
或转义它们
\"string\"- 它更长,但语法有效。 -
下面给出的答案,回答了您发布的内容的问题,应标记为正确。