如何在电子邮件中检索多个数据? [英] How to retrieve more than one data in email?
本文介绍了如何在电子邮件中检索多个数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我发送电子邮件的编码:
<?php
require'class.phpmailer.php';
$ mail = new PHPMailer();
$ mail-> IsSMTP();
$ mail-> Mailer ='smtp';
$ mail-> SMTPAuth = true;
$ mail-> Host ='smtp.gmail.com'; //ssl://smtp.gmail.com没有工作
$ mail-> Port = 465;
$ mail-> SMTPSecure ='ssl';
// ========获取数据库数据==================
$ link =的mysql_connect( 本地主机, 根, );
$ database =master_inventory;
mysql_select_db($ database,$ link)OR die(Could not open $ database);
$ query ='SELECT Lap_PC_Name,Lap_War_Expiry FROM laptop'; // xyz是所需用户的
名称的id。
$ result1 = mysql_query($ query);
while($ row = mysql_fetch_array($ result1)){
$ Lap_PC_Name = $ row ['Lap_PC_Name'];
$ Lap_War_Expiry = $ row ['Lap_War_Expiry'];
}
$ mail->用户名=email@gmail.com;
$ mail-> Password =somepassword;
$ mail-> IsHTML(true); //如果要发送HTML格式的电子邮件
$ mail-> SingleTo = true;
$ mail-> From =email@gmail.com;
$ mail-> FromName =AMS;
$ mail-> addAddress(emailaddress,AMS);
$ mail-> Subject =保修期满通知;
$ mail-> Body =亲爱的女士,< br />< br />以下电脑的许可证将在不到一个月内到期
< br /> ;< br /> PC名称:$ Lap_PC_Name。 < br />过期日期:
。$ Lap_War_Expiry;
if(!$ mail-> Send())
echo未发送消息< br /> PHPMailer错误:。 $ MAIL-> ERRORINFO;
else
echo已发送消息;
?>
解决方案
您需要从而
循环到它。
编辑
更改
while($ row = mysql_fetch_array($ result1)){
$ Lap_PC_Name = $ row ['Lap_PC_Name'];
$ Lap_War_Expiry = $ row ['Lap_War_Expiry'];
}
to
while($ row = mysql_fetch_array($ result1)){
$ Lap_PC_Name = $ row ['Lap_PC_Name'];
$ Lap_War_Expiry = $ row ['Lap_War_Expiry'];
$ mail->用户名=email@gmail.com;
$ mail-> Password =somepassword;
$ mail-> IsHTML(true); //如果要发送HTML格式的电子邮件
$ mail-> SingleTo = true;
$ mail-> From =email@gmail.com;
$ mail-> FromName =AMS;
$ mail-> addAddress(emailaddress,AMS);
$ mail-> Subject =保修期满通知;
$ mail-> Body =亲爱的女士,< br />< br />以下电脑的许可证将在不到一个月内到期
< br /> ;< br /> PC名称:$ Lap_PC_Name。 < br />过期日期:
。$ Lap_War_Expiry;
if(!$ mail-> Send())
echo未发送消息< br /> PHPMailer错误:。 $ MAIL-> ERRORINFO;
else
echo已发送消息;
}
I have a table named 'laptop' and a column inside the table named 'Lap_War_Expiry'. I need to send an email to user when the warranty of the laptop is going to expire soon. For your information, there is more than one warranty that will expired in a day. But the code below is only send the same data from table 'laptop'. Why is that happened and what I have to add in the code so that the email send will retrieve two or more data from database ?
This is my coding for sending the email :
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
// ======== get database data ==================
$link = mysql_connect("localhost","root","");
$database="master_inventory";
mysql_select_db ($database,$link) OR die ("Could not open $database" );
$query = 'SELECT Lap_PC_Name, Lap_War_Expiry FROM laptop'; //xyz is id of desired user
name.
$result1 = mysql_query($query);
while($row = mysql_fetch_array($result1)) {
$Lap_PC_Name = $row['Lap_PC_Name'];
$Lap_War_Expiry = $row['Lap_War_Expiry'];
}
$mail->Username = "email@gmail.com";
$mail->Password = "somepassword";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true;
$mail->From = "email@gmail.com";
$mail->FromName = "AMS";
$mail->addAddress("emailaddress","AMS");
$mail->Subject = "Notification on warranty expiry";
$mail->Body = "Dear Madam,<br/><br />The licensed for the following PC will expired
in less than one month.<br /><br /> PC Name : ".$Lap_PC_Name. "<br />Date of expired :"
.$Lap_War_Expiry;
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
解决方案
You need to move everything from below your while
loop into it.
EDIT Change
while($row = mysql_fetch_array($result1)) {
$Lap_PC_Name = $row['Lap_PC_Name'];
$Lap_War_Expiry = $row['Lap_War_Expiry'];
}
to
while($row = mysql_fetch_array($result1)) {
$Lap_PC_Name = $row['Lap_PC_Name'];
$Lap_War_Expiry = $row['Lap_War_Expiry'];
$mail->Username = "email@gmail.com";
$mail->Password = "somepassword";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true;
$mail->From = "email@gmail.com";
$mail->FromName = "AMS";
$mail->addAddress("emailaddress","AMS");
$mail->Subject = "Notification on warranty expiry";
$mail->Body = "Dear Madam,<br/><br />The licensed for the following PC will expired
in less than one month.<br /><br /> PC Name : ".$Lap_PC_Name. "<br />Date of expired :"
.$Lap_War_Expiry;
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
}
这篇关于如何在电子邮件中检索多个数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文