2013-03-14 40 views
0

我正在運行phpmailer,它非常新。 問題定義:無法看到收到的電子郵件中的PHP變量數據,而html內容可以正常顯示。 下面是一些代碼:phpmailer for php變量

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也是每個郵件的動態數據。

請幫忙。

回答

2

你不能把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>'; 
0

你需要把之間的「不是」的文字。

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> 
"; 
0

嘗試,而不是:

$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代碼會在字符串正弦e你已經在php環境中了!

0

更換機身採用:

$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>'; 
0
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

    $message .= "Phone: 0181-4606260.<br>"; 
$message .="Mobile :09417608422.<br>"; 

Send_Mail('[email protected]','Welcome',$message,$headers); 

試試這個...

+0

你把PHP變量這樣的,並嘗試發送郵件。它會工作很好.. – Manik 2013-03-14 11:09:00