简体   繁体   English

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

[英]sending an email in php to an address stored in database

I am trying to send an email with PHP, but I want the recipients to be an email which is stored in my database.我正在尝试使用 PHP 发送电子邮件,但我希望收件人是存储在我的数据库中的电子邮件。

Here is some code这是一些代码

$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();

Here is the email which is being send, its pullin in from a form which the user fills out这是正在发送的电子邮件,它从用户填写的表格中提取

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';

You need to query your database.您需要查询您的数据库。 Please have a read of this tutorial for mysqli http://www.w3schools.com/php/php_ref_mysqli.asp请阅读本教程的 mysqli http://www.w3schools.com/php/php_ref_mysqli.asp

You will need something like this.你会需要这样的东西。

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

And then put $email in the setTo parameter.然后将 $email 放入 setTo 参数中。

This tutorials better actually.这个教程实际上更好。 http://codular.com/php-mysqli http://codular.com/php-mysqli

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM