我正在运行phpmailer,并且对它非常陌生。问题定义:无法在收到的电子邮件中查看php变量数据,而html内容可以正确查看。以下是一些代码:
require 'PHPMailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Message';
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong> <?php echo "$name";?> <?php echo "$place";?>
</body>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
无法查看php下定义的数据。$name和$place也是每个邮件的动态数据。
请帮忙。
不能将php语句放在单引号中。请使用以下内容:
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>' . $name . ' ' . $place . '
</body>';
您需要将文本放在"而不是'.之间
PHP只替换双引号字符串中的变量。
此外,您不应该在字符串中使用php代码。
$mail->Body = "
<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong> $name $place
</body>
";
改为尝试:
$mail->Body = "<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>$name $place
</body>";
您不必在字符串中放置php标记,因为您已经在php上下文中了!
将Body替换为:
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>'.$name.' '.$place.'</body>';
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$message .= "Phone: 0181-4606260.<br>";
$message .="Mobile :09417608422.<br>";
Send_Mail('abc@example.com','Welcome',$message,$headers);
试试这个。。。