php - 将表单信息发送到存储在数据库中的电子邮件

标签 php mysql database email

我一直在研究这个问题,但无法得到答案。 我有一个将信息发送到我的数据库的表单,我还希望将信息发送到存储在数据库表中的列中的电子邮件地址。这是代码,我只是想看看是否可以执行 SELECT 查询,但它不起作用,而且我知道当我手动将地址放入“setTo”时发送电子邮件可以工作

require 'mail/class.simple_mail.php';
$mailer = new SimpleMail();

$comments = $_REQUEST['comments'];
$time = $_REQUEST['time'];
$date = $_REQUEST['date'];
$place = $_REQUEST['place'];
$email = "SELECT email FROM bridesmaids";

$message = "<strong>This is an email from the bride to you the bridesmaids, here is the information on the next dress fitting<br />".$date." ".$time." ".$place." ".$comments." </strong>";



$send   = $mailer->setTo('$email', 'Your Email')
                 ->setSubject('Dress Fitting')
                 ->setFrom('donaghy-e5@email.ulster.ac.uk', 'Domain.com')
                 ->addMailHeader('Reply-To', 'donaghy-e5@email.ulster.ac.uk', 'Domain.com')
                 ->addMailHeader('Cc', 'donaghy-e5@email.ulster.ac.uk', 'Bill Gates')
                 ->addGenericHeader('Content-Type', 'text/html; charset="utf-8"')
                 ->setMessage($message)
                 ->setWrap(100)
                 ->send();
echo ($send) ? 'Your Email has been sent to your bridesmaids' : 'Could not send email';

最佳答案

如果您尚未创建 SQL 连接,请先执行此操作:

1:从伴娘表中选择您的电子邮件 - 然后将结果返回到数组中 (PDO::FETCH_ASSOCfetch_array(MYSQLI_ASSOC)) 并将该数组绑定(bind)到一个变量,例如$mailingList

2:将邮件程序代码包装在 foreach 循环 ( http://uk3.php.net/manual/en/control-structures.foreach.php ) 中,示例如下:

foreach($mailingList as $value) {

    // your mailer code here, replace $email with $value
    $send   = $mailer->setTo($value, 'Your Email')
    // $value will update for each iteration with your emails

}

3:确保不需要重复的任何代码或变量都在循环之外。

关于php - 将表单信息发送到存储在数据库中的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22986162/

相关文章:

php - 使用一列中的多个值规范化 MySQL 数据库

php - 用于页面处理的 RewriteRule 给出目标页面名称而不是请求

php - 多个文件上传时的 Laravel 5 TokenMismatchException

PHP OOP 类设计

php - 编码 hell 。 MySQL、PHP 和 utf-8

mysql - 在单个查询中从多个表中获取数据

PHP+MS Access : Wildcard * being taken as a string when querying through PHP?

php - 在 PHP 中,如何向从 iPhone InApp 收据检索到的购买日期添加 3 个月?

php - 在不严重影响数据库的情况下在分页表中显示大量数据

mysql - 在 mysql 数据库中存储友谊协会的正确方法是什么