2010-10-18 60 views
0

如何添加php for循環腳本以在電子郵件中生成內容(從數據庫中接收),如下面突出顯示的那樣?

$message = " 
<html> 
<head> 
<title>Your's Weekly Newsletter </title> 
</head> 
<body> 
<p>Hi $to,</p> 
<p>Here are the highlight of the deals this week:</p> 
<br /> 

<p> **<?php 
    for ($i=0;$i<=$totalCount;$i++) { 
    echo \"Deal Description = $HighlightWeeklyNewsletter_array2[$i] <br />\"; 
    echo \"Deal URL = <a href=\"$HighlightWeeklyNewsletter_array3[$i]\"> More >> $HighlightWeeklyNewsletter_array1[$i] </a> <br />\"; 
    echo \"Days Left = $HighlightWeeklyNewsletter_array4[$i] <br />\"; 

    echo \" <hr width=\"auto\" style=\"border: 1px dotted #000000\" size=\"1\"> \"; 
    } 
?>** 
</p> 

<p> <u>Forward this email</u> to your friends/family and let them know you like this. </p> 
<br /> 
</body> 
</html> 
"; 

回答

1

您不能在PHP字符串的內容中嵌入php代碼。你必須像這樣拆分它:

$message = " 
<html> 
<head> 
<title>Your's Weekly Newsletter </title> 
</head> 
<body> 
<p>Hi $to,</p> 
<p>Here are the highlight of the deals this week:</p> 
<br /> 

<p> **"; 
for ($i=0;$i<=$totalCount;$i++) { 
    $message .= "Deal Description = " . $HighlightWeeklyNewsletter_array2[$i] . "<br />"; 
    $message .= "Deal URL = <a href=\"" . $HighlightWeeklyNewsletter_array3[$i] . "\"> More >> " . $HighlightWeeklyNewsletter_array1[$i] . "</a> <br />"; 
    $message .= "Days Left = " . $HighlightWeeklyNewsletter_array4[$i] . "<br />"; 
    $message .= "<hr width=\"auto\" style=\"border: 1px dotted #000000\" size=\"1\">"; 
} 

$message .= "** 
</p> 

<p> <u>Forward this email</u> to your friends/family and let them know you like this. </p> 
<br /> 
</body> 
</html> 
";