使用复选框将使用phpMailer的电子邮件发送到数据库中的多个收件人到选定的电子邮件地址
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用复选框将使用phpMailer的电子邮件发送到数据库中的多个收件人到选定的电子邮件地址,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2703字,纯文字阅读大概需要4分钟。
内容图文
我目前正在使用php mysql基本系统,该系统将通过功能上的复选框将电子邮件从数据库发送给多个收件人.
如何使用“检查所有功能”向那些收件人发送电子邮件?
这是我的phpMailer代码,可以正常工作
<?php
require("class.phpmailer.php");
include("class.smtp.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.gmail.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'myemail@gmail.com';
$mailer->Password = 'mypassword';
$mailer->From = 'myemail@gmail.com';
$mailer->FromName = 'Admin';
$mailer->Body = 'TEST EMAIL';
$mailer->Subject = 'This is the subject of the email';
$mailer->AddAddress('myrecipient@yahoo.com');
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
我当前在系统中使用的另一个示例代码,用于通过复选框功能从数据库中删除用户:
<?php
/*Check Box Commands*/
$id=$row_notification['user_id'];
if(isset($_POST['Delete'])) {
$checkbox = $_POST['checkbox'];
mysql_select_db($database_connection_ched, $connection_ched);
$id=$row_notification['user_id'];
for($i=0;$i<count($checkbox);$i++)
{
$delete = "DELETE FROM tb_user WHERE user_id=$checkbox[$i]";
mysql_query($delete,$connection_ched);
}
$result2 = mysql_query($delete);
if($result2)
{
echo "<script language='javascript'>alert ('Successfully Deleted');</script>";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=notification.php?\">"; }
}
/*End of Checkbox Commands*/
?>
解决方法:
您可以从那里的删除代码中使用一些逻辑,但是也可以通过只调用一次数据库来获取信息来改进它:
<?php
require("class.phpmailer.php");
include("class.smtp.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.gmail.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'myemail@gmail.com';
$mailer->Password = 'mypassword';
$mailer->From = 'myemail@gmail.com';
$mailer->FromName = 'Admin';
$mailer->Body = 'TEST EMAIL';
$mailer->Subject = 'This is the subject of the email';
// get checkbox ids posted to us
$checkbox_ids = $_POST["checkbox"];
// get email addresses from db based on checkboxes posted to us
$query = "select email from tb_user where user_id in(".join(",",$checkbox_ids).")";
// connect to db and run query
mysql_select_db($database_connection_ched, $connection_ched);
$result = mysql_query($query);
while( $data = mysql_fetch_assoc($result) )
{
// make SURE we are not sending this to each and every recipient incrementally.
// alternately, you can use $mailer->ClearAllRecipients(); <-- this will clear cc and bcc as well
$mailer->ClearAddresses();
// send it to THIS user...
$mailer->AddAddress($data["email"]);
print ($mailer->Send()) ? "Message sent to: " : "Message <b>not</b> sent to: ";
print $data["email"]."<br />\n";
}
?>
内容总结
以上是互联网集市为您收集整理的使用复选框将使用phpMailer的电子邮件发送到数据库中的多个收件人到选定的电子邮件地址全部内容,希望文章能够帮你解决使用复选框将使用phpMailer的电子邮件发送到数据库中的多个收件人到选定的电子邮件地址所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。