Home  >  Article  >  Backend Development  >  高手!高手!请进来看一下!有关复杂邮件的一个功能!解决方法

高手!高手!请进来看一下!有关复杂邮件的一个功能!解决方法

WBOY
WBOYOriginal
2016-06-13 13:45:01800browse

高手!!高手!!请进来看一下!!有关复杂邮件的一个功能!!!
折腾一周没做出来的一个东东,今天周末加班还是没有战果,初次接触程序啊,还望高手多多指点!!!!在此先谢过!!!

需求:
做一个合同模块,分多段提醒,我现在只做了两段提醒。

即:
只要检测到sdate,edate 有与当前系统时间(2008-7-19)时间相同的都得那行邮件地址发送一份邮件.

数据库设置:
sdate edate email name
2008-7-11 2008-7-19 adfd@aa.com adfd
2008-7-15 2008-7-19 bbcc@aa.com bbcc

2008-7-19 2008-7-22 xxbb@aa.com xxbb
2008-7-19 2008-7-28 ccbb@aa.com ccbb



基本实现思路:

我现在用了一个phpmailer的类来做。(环境是:linux+apache+php+mysql)

写了一个cron.php的文件(如下:),用crontab每天刷新一次cron.php页面

判断当当前系统时间与2008-7-19一致,如果是一致就发邮件
照上面数据的数据,检测到sdate有二条2008-7-19,edate有二条2008-7-19,就得发四个邮件提醒这四个用户。


现在我的程序出现问题: 就是每次只会去取其中一条记录,而且只会对这一条记录发邮件,而其它三条相同的时间,就没办法达到提醒功能;

非常急切,请大家帮忙!!!非常感谢感谢!!



//cron.php的文件如下:

date_default_timezone_set('Asia/Shanghai'); 
$datesy=date("Y-m-d"); //当前系统时间

//$format="

%s %s %s %s %s %s"; 

$db=mysql_connect('localhost','root','');
mysql_select_db('test',$db);
$sql="select sdate,edate,email,name from testmail"; //sdate 与edate字段分别对应数据库中的两段时间
mysql_query("set names gb2312"); 
$result=mysql_query($sql,$db);

while ($row = mysql_fetch_array($result))  
  {
   
   
  printf ($format,$row[0],$row[1],$row[2],$row[3],$row[4],$row[5]); 


if($datesy==$row[0] || datesy==$row[1]) //目前是:如果定点刷新页面,程序只会去检测$row[1] 也就是edate时间,只会取一个而发送邮件,如果edate有2条或更多为2008--7-19的时间,都不会发邮件。我的目的是要:如果sdate ,date 哪怕是一百行数据,只要是与当前时间一致,都要发邮件。
{

require("phpmailer/class.phpmailer.php");
   
$mail = new PHPMailer();
$address=$row[1];

$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.aaa.com.cn"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "Josh"; // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From = "Josh@aaa.com.cn";
$mail->FromName = "Mailer";
$mail->AddAddress("$address", "Josh Adams");
$mail->AddAddress("xx@bbb.com.cn"); // name is optional
$mail->AddReplyTo("xx@bbb.com.cn", "Information");

$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$mail->IsHTML(true); // set email format to HTML
$name="$row[2]";
$mail->Subject ="$name 到期了";
$mail->Body = "This is the HTML message body in bold!";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
  echo "Message could not be sent.

";
  echo "Mailer Error: " . $mail->ErrorInfo;
  exit;
}

echo "Message has been sent";
}
   
  // }

else 
{
echo "不成功";
}

  }


mysql_close(); 



?>





------解决方案--------------------
关键是$address=$row[1]; 
错了
------解决方案--------------------

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn