mysql到php电子邮件设置

时间:2015-05-08 03:21:30

标签: php mysql email-integration

我正在尝试向我的mysql表中的电子邮件地址发送一封电子邮件,其中包含该行的信息。我的代码在日期,时间停止并发送检查。我不确定这条线。请参阅下面的代码。它只是一个PHP文件,因为这将成为一个cron作业。

我的日期和时间由输入数据的人输入。 日期格式:2015-05-07 时间格式:14:32

我收到此错误 您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在':06 ||附近使用正确的语法sent = NULL'在第1行

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<?php

require ('class.phpmailer.php');
require ('login.php');

$link = mysql_connect($REMINDER_DB_HOST, $REMINDER_DB_USER, $REMINDER_DB_PASSWORD);

if (!link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($REMINDER_DB_NAME, $link);

if (!db_selected) {
die('Can\'t use ' . DB_NAME . ' : ' . msql_error());
}
$today = date("Y-m-d");
$now = date("H:i");

echo $today;
echo $now;

$sql = mysql_query("SELECT * FROM alert WHERE date < $today || time < $now || sent = NULL") or die(mysql_error());

while($row = mysql_fetch_assoc($sql)) {


$name = $row['name'];
$to = $row['email'];
$date = $row['date'];
$time = $row['time'];
$eslticket = $row['eslticket'];
$notes = $row['notes'];

$mail = new PHPMailer;

$g_smtp_connection_mode   = 'ssl';
$g_phpMailer_method        = 2;
$g_smtp_host              = 'smtp.gmail.com';
$g_smtp_port              = 465;
$g_smtp_username          = $mailuser;
$g_smtp_password          = $mailpassword;



$subject = 'ESL Ticket Reminder: ' .$eslticket;
$msg = 'Good Day, '.$name.'\n'.'You have requested an alert email to be sent to you about '.$eslticket.' on '.$date.' at '.$time.'. Please see below to review your notes on this ticket.'.'\n'.'\n'.$notes;

if(mail($to, $subject, $msg)) {
$sql = "INSERT INTO alert (sent) VALUES ('1')";
} else {

}

}
?>
</head>
<body>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

$sql = mysql_query("SELECT * FROM alert WHERE date < '$today' OR time < '$now' OR sent = NULL") or die(mysql_error());