Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在电子邮件中从数据库检索数据_Php_Email - Fatal编程技术网

Php 在电子邮件中从数据库检索数据

Php 在电子邮件中从数据库检索数据,php,email,Php,Email,我正在使用sendmail以php发送电子邮件。问题是,我想在邮件中检索数据库中的详细信息。我该怎么做?这是我的密码 <?php // set database server access variables: $host = "localhost"; $user = "root"; $pass = ""; $db = "master_inventory"; // open connection $connection = mysql_connect($host, $user,

我正在使用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";

?>

但是这些
mysql.*
函数被贬低了,请使用试试这个

$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";
}

使用@sign忽略错误

那么,在这种情况下,我应该如何使用PDO?电子邮件发送仍然打印出该行,而没有检索数据。例如,以下您的产品过期产品代码:.$Desk\u PC\u name您的查询有问题不要选择所有记录,只选择与接收您问题的电子邮件的人相关的记录。
$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";
}