gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:03:54 25 4
gpt4 key购买 nike

我一直在研究这个问题,但无法得到答案。我有一个将信息发送到我的数据库的表单,我还希望将信息发送到存储在数据库表中的列中的电子邮件地址。这是代码,我只是想看看是否可以执行 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com