PHP从正文内容中创建变量。

时间:2013-07-16 05:00:19

标签: php html email

无论如何,让变量等于身体的内容?

示例:

<?php 

//PHP

$body = { ?>

<!-- HTML -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>


<?php } ?>

这样我就可以用它发送电子邮件了。

$success = mail($EmailTo, $Subject, $Body, 'From: <$EmailFrom>');

4 个答案:

答案 0 :(得分:4)

是 - 使用输出缓冲功能:

ob_start();

// Echo your output here or

?>

<div>Just output your HTML like this</div>

<?php

$output = ob_get_clean();

答案 1 :(得分:3)

您可以在PHP中使用heredoc

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

答案 2 :(得分:1)

试试这个

<? 

$body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
$body .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
$body .= "<head>"
$body .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
$body .= "<title>Untitled Document</title>"
$body .= "</head>"
$body .= "<body>"
$body .= "</body>"
$body .= "</html>"

?>

答案 3 :(得分:0)

check this way

<?php 

//PHP

$body = '

<!-- HTML -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>';

 ?>