PHP-查询数据库中的挂起消息,并在不刷新的情况下调用PHPmailer


PHP - Query database for pending messages and call PHPmailer without refresh

我使用的是phpMailer,我有一个数据库表"list",列为id|name|email|status。

我目前正在使用phpMailer示例

date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail                = new PHPMailer();
$body                = file_get_contents('contents.html');
$body                = eregi_replace("[']",'',$body);
$id = $_GET['id'];
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host          = "smtp1.xample.com;smtp2.xample.com";
$mail->SMTPAuth      = true;                  // enable SMTP authentication
$mail->SMTPKeepAlive = true;                  // SMTP connection will not close after each email sent
$mail->Host          = "mail.example.com"; // sets the SMTP server
$mail->Port          = 25;                    // set the SMTP port for the GMAIL server
$mail->Username      = "no-reply@example.com"; // SMTP account username
$mail->Password      = "password";        // SMTP account password
$mail->SetFrom('no-reply@example.com', 'Honda example');
$mail->AddReplyTo('no-reply@example.com', 'Honda example');
$mail->Subject       = "PHPMailer Test Subject via smtp, basic with authentication";
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("osher");
$query  = "SELECT full_name, email, photo FROM employee WHERE id=$id";
$result = @MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result)) {
  $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  $mail->MsgHTML($body);
  $mail->AddAddress($row["email"], $row["full_name"]);
  $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
  if(!$mail->Send()) {
    echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
  } else {
    echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br />';
  }
  // Clear all addresses and attachments for next loop
  $mail->ClearAddresses();
  $mail->ClearAttachments();
}

现在上面的代码是db-email.php,在我的表中,电子邮件有100多个状态为挂起的条目,我希望能够使用php。选择每一行id并调用db-email.php?id=xx(其中x是id),从而发送电子邮件。

如果是手动完成的,这项工作会很好。

我需要你们帮我,我如何最好地自动化这个过程,也就是说,能够推送这100封电子邮件(无需刷新页面)

假设我在email.php上,我可能会点击(一个按钮),它会简单地开始处理电子邮件表中的每一行(而不是回复结果),我会更新数据库,状态为="已发送"

我不确定我是否已经很清楚我想问什么,请帮助朋友。我相信在jQuery/AAJAX或其他方面有专业知识的人可以帮助我完成这项任务:)

我不知道你想做什么,但你不能通过javascriptjquery对数据库或服务器做任何事情,因为在浏览器中执行,而不在服务器上
您可以使用ajax调用服务器上的某些.php文件,并使用一些参数来完成您的工作!