0

sendmail を使用して PHP でメールを送信しています。問題は、メール内のデータベースで詳細を取得したいということです。どうやってやるの ?これが私のコードです。

<?php
// set database server access variables: 
$host = "localhost"; 
$user = "root"; 
$pass = ""; 
$db = "master_inventory";

// open connection 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 

// select database 
mysql_select_db($db) or die ("Unable to select database!"); 

// create query 
$query = "SELECT * FROM desktop"; 

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 

// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 

$to       = 'nazasdei@domain.com';
$subject  = 'warranty licensed expired';
$message  = 'The Following Your Product Expired
          Product Code:.$row[Desk_PC_Name]';
$headers  =  'From: miloe@gmail.com' . "\r\n" .
             'Reply-To: miloe@gmail.com' . "\r\n" .
             'MIME-Version: 1.0' . "\r\n" .
             'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
             'X-Mailer: PHP/' . phpversion();
}       
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";

?>
4

2 に答える 2

0

これを試して

$query = "SELECT * FROM desktop";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
while($row = mysql_fetch_array($result)){
   $Desk_PC_Name = $row['Desk_PC_Name'];
}
$to       = "nazasdei@domain.com"; // You can use email from database like this $row['email'];
$subject  = "warranty licensed expired";
$message  = "The Following Your Product Expired
          Product Code:.$Desk_PC_Name";

$headers  =  'From: miloe@gmail.com' . "\r\n" .
             'Reply-To: miloe@gmail.com' . "\r\n" .
             'MIME-Version: 1.0' . "\r\n" .
             'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
             'X-Mailer: PHP/' . phpversion();       
if(@mail($to, $subject, $message, $headers)) {
   echo "Email sent";
} else {
   echo "Email sending failed";
}

エラーを無視するには @ 記号を使用します

于 2013-09-09T05:52:57.660 に答える