2012-06-05 21 views
0

我一直在嘗試過去的幾個小時內在電子郵件中創建一個動態表..我一直unsuccuessful我已經試圖創建表進出身體變量和回聲它內,但我沒有成功,我已經放置我的代碼bellow .. anyhelp將非常感謝..所有即時通訊要做的是創建一個表中的一些MySQL數據,然後將其發送給一些客戶端..這只是一個運行我一直attemoting完成電子郵件中的動態表

$link = mysql_connect('localhost', 'root', ''); 
    mysql_select_db('netbookdb'); 
    $sql="SELECT * FROM rep_log WHERE s_date = '2012-05-31'"; 
    $result=mysql_query($sql, $link); 


$date=date('dmy'); 
require("../PHPMailer/class.phpmailer.php"); 
$mail = new PHPMailer();$mail = new PHPMailer(); 
$mail->IsSMTP(); // set mailer to use SMTP 
$mail->Host = "smtp"; // specify main and backup server 

$mail->From = "[email protected]";  
$mail->FromName = "Ict Devices"; 
$mail->AddAddress("[email protected]", "Matthew"); 


$mail->Subject = "Damage Log Report"; 

$mail->IsHTML(true); 
$var='xlsx'; 
$date=date('dmy.'); 

$mail->Body = " while($rows=mysql_fetch_array($result)){ 
     $cases=$rows['cases']; 
     $hg=$rows['hg']; 
     $surname=$rows['surname']; 
     $firstname=$rows['firstname']; 
     $claim=$rows['claim']; 
     $damage=$rows['damage']; 
     $cost=$rows['cost']; 

    }"; 
$mail->AltBody="Please Use a Html Compaible Email Veiwer"; 



if(!$mail->Send()) 
{ 
    echo "Error sending: " . $mail->ErrorInfo;; 
} 
else 
{ 
    echo "Letter is sent"; 
} 

回答

1

我使用這個代碼的和平,我創建拿到腳本來創建一個動態表,然後只回聲它進入人體電子郵件這也只是一個基本的表格但可以進行改進

$link = mysql_connect('localhost', 'root', ''); 
    mysql_select_db('Your Dataabse name'); 
    $sql="SELECT * FROM rep_log WHERE claim='Insurance' AND s_date = '2012-05-31'"; 
    $result=mysql_query($sql, $link); 

$table= "<table width='100%' border='3' cellspacing='0' cellpadding='0'>"; 
$table .="<th>Cases</th>"; 
$table .="<th>HG</th>"; 
$table .="<th>Surname</th>"; 
$table .="<th>FristName</th>"; 
$table .="<th>Claim</th>"; 
$table .="<th>Damage</th>"; 
$table .="<th>Cost</th>"; 

    while($rows=mysql_fetch_array($result)){ 
     $cases=$rows['cases']; 
     $hg=$rows['hg']; 
     $surname=$rows['surname']; 
     $firstname=$rows['firstname']; 
     $claim=$rows['claim']; 
     $damage=$rows['damage']; 
     $cost=$rows['cost']; 
    $table .="<tr>"; 
    $table .="<td>$cases</td>"; 
    $table .="<td>$hg</td>"; 
    $table .="<td>$surname</td>"; 
    $table .="<td>$firstname</td>"; 
    $table .="<td>$claim</td>"; 
    $table .="<td>$damage</td>"; 
    $table .="<td>$cost</td>"; 
    $table .="</tr>"; 


    } 
$table .="</table>"; 

$date=date('dmy'); 
require("../PHPMailer/class.phpmailer.php"); 
$mail = new PHPMailer();$mail = new PHPMailer(); 
$mail->IsSMTP(); // set mailer to use SMTP 
$mail->Host = "smtp"; // specify main and backup server 

$mail->From = "[email protected]";  
$mail->FromName = "Ict Devices"; 
$mail->AddAddress("[email protected]", "Matthew"); 


$mail->Subject = "Damage Log Report"; 

$mail->IsHTML(true); 
$var='xlsx'; 
$date=date('dmy.'); 

$mail->Body = "$table;"; 
$mail->AltBody="Please Use a Html Compaible Email Veiwer"; 



if(!$mail->Send()) 
{ 
    echo "Error sending: " . $mail->ErrorInfo;; 
} 
else 
{ 
    echo "Letter is sent"; 
} 
相關問題