将php中的电子邮件发送到存储在数据库中的地址

时间:2014-04-16 12:03:10

标签: php mysql database email

我正在尝试使用PHP发送电子邮件,但我希望收件人成为存储在我的数据库中的电子邮件。

这是一些代码

$send  = $mailer->setTo('email@example.com', 'Your Email')
                 ->setSubject('Example')
                 ->setFrom('example@email.com', 'test')
                 ->addMailHeader('Reply-To', 'example@test.com', 'test')
                 ->addMailHeader('Cc', 'edonaghy--@hotmail.co.uk', 'test')
                 ->addGenericHeader('Content-Type', 'text/html; charset="utf-8"')
                 ->setMessage($message)
                 ->setWrap(400)
                 ->send();

这是正在发送的电子邮件,它从用户填写的表单中拉入

mysql_select_db("lr", $con);
require 'mail/class.simple_mail.php';
$mailer = new SimpleMail();

$comments = $_REQUEST['comments'];
$time = $_REQUEST['time'];
$date = $_REQUEST['date'];
$place = $_REQUEST['place'];

$message = "<strong>This is an email from the bride to you the bridesmaids, here is the information on the next dress fitting<br />Date:".$date."<br />Time: ".$time."<br /> Place:".$place."<br />Any other comments: ".$comments." </strong>";
if ($send) {echo 'Your Email has been sent';}else {
echo 'An error occurred. We could not send email';

1 个答案:

答案 0 :(得分:2)

您需要查询您的数据库。请阅读本教程中的mysqli http://www.w3schools.com/php/php_ref_mysqli.asp

你需要这样的东西。

$qry = "SELECT email FROM users WHERE username = ?'"
$stmt = $mysqli->prepare($qry);
$stmt->bind_param('s', 'someone'):
$stmt->execute();
$stmt->bind_result($email);

然后将$ email放入setTo参数。

本教程实际上更好。 http://codular.com/php-mysqli