PHP发送电子邮件foreach用户 [英] PHP send email foreach user

查看:241
本文介绍了PHP发送电子邮件foreach用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于此页面,我需要从管理员的电子邮件中发送电子邮件,并发送电子邮件至每个管理者的电子邮件,其中endofmonthdate = 22/09/2016



http://pastebin.com/7PD2MyuC



提前谢谢!

解决方案

您的代码缺少一些大括号({}):

  include(../dbconnect.php); 

$ sql ='SELECT c.endofmonthform,c.startofmonthform,c.email,c.id,c.formlevel,c.mastersite,c.opmanager,u.userEmail FROM`clients` as c LEFT JOIN`users` as u on c.opmanager = u.userName WHERE endofmonthform =22/09/2016'; //今天晚上回来了!

$ result = mysql_query($ sql);

while($ row = mysql_fetch_array($ result)){

$ enddate = $ row ['endofmonthform']; // End

$ startdate = $ row ['startofmonthform']; //开始

$ email = $ row ['email']; //电子邮件发送电子邮件到

$ id = $ row ['id'];

$ formlevel = $ row ['formlevel']; //更新并检查formlevel

$ sitegroupname = $ row ['mastersite'];

$ manager = $ row ['opmanager'];

$ opemail = $ row ['userEmail'];

/ *如果结束日期是今天,表单级别仍然为零,然后发送电子邮件至op manager * /
$ mail = new EMail;

$ mail->用户名='发件人电子邮件';
$ mail-> Password ='mypwd';
$ mail-> SetFrom(senderemail@example.com,companyname);
$ mail-> ContentType =text / html;
$ mail-> Subject =客户反馈不完整新布局;

//输入您要发送的电子邮件地址(名称是可选的友好名称):
$ mail-> AddTo($ opemail,$ manager);


$ mail-> Message =<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR /xhtml1/DTD/xhtml1-transitional.dtd>
< html xmlns = http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv = Content-Type content = text / html; charset = utf-8 />
< title>< / title>
< style type = text / css>
body {margin:0; padding:0; min-width:100%!important;}
.content {width:100%; max-width:600px;}
< / style>
< / head>
< body yahoo bgcolor =#f6f8f1>
< table width = 100%bgcolor =#f6f8f1 border = 0 cellpadding = 0 cellspacing = 0>
< tr>
< td>
< table class = content align = center cellpadding = 0 cellspacing = 0 border = 0>
< tr>
< td>

ID:$ id。< br>

客户端组名称:。$ sitegroupname。< br>

管理rs名称:。$ manager。< br>

经理电子邮件:$ useremail。 <峰; br>

请按照您的反馈通知登录您的帐户
< br>

< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>
< / body>
< / html>;

echo $ success = $ mail-> Send(); //发送电子邮件
}

还清理了一些PHP来简化整个事情
注意:我排除了电子邮件类,因为它是' t / b> b

TS通知我邮件部分不工作,所以尝试使用默认的php邮件程序:

 <?php 
include(../dbconnect.php );

$ sql ='SELECT c.endofmonthform,c.startofmonthform,c.email,c.id,c.formlevel,c.mastersite,c.opmanager,u.userEmail FROM`clients作为c LEFT JOIN`users`作为你在c.opmanager = u.userName WHERE endofmonthform =22/09/2016'; //今天的日期返回这里

$ result = mysql_query($ s $)

while($ row = mysql_fetch_array($ result)){

$ enddate = $ row ['endofmonthform']; // End

$ startdate = $ row ['startofmonthform']; //开始

$ email = $ row ['email ]; //电子邮件发送电子邮件至

$ ID = $行[身份证];

$ formlevel = $ row ['formlevel']; //更新并检查formlevel

$ sitegroupname = $ row ['mastersite'];

$ manager = $ row ['opmanager'];

$ opemail = $ row ['userEmail'];

mail($ opemail,subject,message,from);
}


For this page i need to get managers email from users and send email to each managers email where the endofmonthdate = 22/09/2016

http://pastebin.com/7PD2MyuC

Thank you in advance!!

解决方案

Your code was missing some curly brackets ( {} ):

include ("../dbconnect.php");

$sql='SELECT c.endofmonthform, c.startofmonthform, c.email, c.id, c.formlevel, c.mastersite, c.opmanager, u.userEmail FROM `clients` as c LEFT JOIN `users` as u on c.opmanager = u.userName WHERE endofmonthform="22/09/2016"'; //TODAYS DATE BACK HERE!

$result=mysql_query($sql); 

 while($row=mysql_fetch_array($result)){  

    $enddate = $row['endofmonthform']; // End

    $startdate = $row['startofmonthform']; // Start

    $email = $row['email']; //Email to send email to

    $id = $row['id'];

    $formlevel = $row['formlevel']; //To update and check formlevel

    $sitegroupname = $row['mastersite'];

    $manager = $row['opmanager'];

    $opemail = $row['userEmail'];

    /* If end date is today and form level is still ZERO then send email to op manager */
    $mail = new EMail;

    $mail->Username = 'Sender email';    
    $mail->Password = 'mypwd';
    $mail->SetFrom("senderemail@example.com","companyname");  
    $mail->ContentType = "text/html";
    $mail->Subject = "Client feedback incomplete NEW LAYOUT";

    //Enter the email address you wish to send TO (Name is an optional friendly name):
    $mail->AddTo($opemail,$manager);


    $mail->Message = "<!DOCTYPE html PUBLIC  -//W3C//DTD XHTML 1.0 Transitional//EN   http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >
    <html xmlns=http://www.w3.org/1999/xhtml>
    <head>
    <meta http-equiv=Content-Type  content=text/html; charset=utf-8 />
    <title></title>
    <style type=text/css >
    body {margin: 0; padding: 0; min-width: 100%!important;}
    .content {width: 100%; max-width: 600px;}  
    </style>
    </head>
    <body yahoo bgcolor=#f6f8f1 >
    <table width=100% bgcolor=#f6f8f1 border=0 cellpadding=0 cellspacing=0>
    <tr>
    <td>
    <table class=content  align=center  cellpadding=0  cellspacing=0  border=0 >
    <tr>
    <td>

    ID: ".$id." <br>

    Clients group name: ".$sitegroupname." <br>

    Managers Name: ".$manager." <br>

    Managers Email: ".$useremail." <br>

    Please log into your account as you have feedback notifications
    <br>

    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>";

    echo $success = $mail->Send(); //Send the email.
}

Also cleaned up some of the PHP to simplify the entire thing. NOTE: I excluded the email class as it isn't relevant to this problem.

EDIT:

TS informed me that the mail part wasn't working, so try using the default php mailer:

<?php 
include ("../dbconnect.php");

$sql='SELECT c.endofmonthform, c.startofmonthform, c.email, c.id, c.formlevel, c.mastersite, c.opmanager, u.userEmail FROM `clients` as c LEFT JOIN `users` as u on c.opmanager = u.userName WHERE endofmonthform="22/09/2016"'; //TODAYS DATE BACK HERE!

$result=mysql_query($sql); 

 while($row=mysql_fetch_array($result)){  

    $enddate = $row['endofmonthform']; // End

    $startdate = $row['startofmonthform']; // Start

    $email = $row['email']; //Email to send email to

    $id = $row['id'];

    $formlevel = $row['formlevel']; //To update and check formlevel

    $sitegroupname = $row['mastersite'];

    $manager = $row['opmanager'];

    $opemail = $row['userEmail'];

    mail($opemail, "subject", "message", "from");
}

这篇关于PHP发送电子邮件foreach用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆