如何从MySQL记录发送自动电子邮件? [英] How can I send an auto email from MySQL records?

查看:576
本文介绍了如何从MySQL记录发送自动电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL数据库和PHP.
我的MySQL数据库包含以下记录:

I am using a MySQL database and PHP.
My MySQL database contains the following records:

  Name  Address    Data    email             Date
  Joy   Fortblair  10     my@gmail.comm    1/22/2009
  Bob   Atlanta    15      bob@gmail.com    2/22/2009

我的意图是在满足以下条件的情况下使用PHP发送电子邮件:

My intention is to send the email using PHP with the following conditions:

  • 数据已存在1天. (Current date - date = 1 day)

它应该一次发送所有电子邮件记录.

It should mail all the email records at one time.

最好的入门方法是什么?

What is the best way to get started?

推荐答案

SQL查询非常简单,如下所示

The SQL query is pretty simple and it goes as following

SELECT *, TIMESTAMPDIFF(day, Date, NOW()) FROM `your_table_name` WHERE TIMESTAMPDIFF(day, Date, NOW()) = 1;

现在,您必须获取结果的内容并将其放在字符串中

Now you have to get the contents of the result and put them in a string

<?php
$sql = " SELECT *, TIMESTAMPDIFF(day, Date, NOW()) FROM `your_table_name` WHERE TIMESTAMPDIFF(day, Date, NOW()) = 1";
$query = mysql_query($query);
$emailBody = "";
while($row = mysql_fetch_assoc($query))
{
   $emailBody .= "Name: ".$row['Name']."; Address: ".$row['Address']."; Data: ".$row['Data']."; Email: ".$row['email']." \n";
}

mail("address@yourdomain.com", "Subject", $emailBody);
?>

享受!

这篇关于如何从MySQL记录发送自动电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆