Master! Master! Please come in and have a look! A feature about complex messages! workaround

Source: Internet
Author: User
Tags word wrap
Master!! Master!! Please come in and have a look!! A feature about complex messages!!!
Toss a week did not make out of an east, this weekend overtime or no victory, the first contact procedure Ah, also look master more pointing!!!! Thank you first!!!

Demand:
Make a contract module, a multi-paragraph reminder, I now only do two reminders.

That
Whenever a sdate,edate is detected that has the same line of time as the current system time (2008-7-19), send a copy of the email address.

Database settings:
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



Basic implementation Ideas:

I now use a Phpmailer class to do it. (Environment is: linux+apache+php+mysql)

Wrote a cron.php file (as follows:), refresh the cron.php page once a day with crontab

Determine when the current system time is consistent with 2008-7-19, and if so, send an email
According to data from the above data, detected Sdate has two 2008-7-19,edate two 2008-7-19, you have to send four e-mails to remind these four users.


Now my program has a problem: that is, each time only to fetch one of the records, and will only send messages to this record, and the other three of the same time, there is no way to achieve the reminder function;

Very anxious, please help!!! Thank you very much thanks!!



The cron.php files are as follows:

Date_default_timezone_set (' Asia/shanghai ');
$datesy =date ("y-m-d"); Current system time

$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 and Edate fields correspond to two time in the database respectively
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])//Current is: If the Point refresh page, the program will only go to detect $row[1] that is edate time, only take one and send mail, If Edate has 2 or more times for 2008--7-19, no email will be sent. My goal is to: if sdate, date even 100 rows of data, as long as the current time is consistent with the e-mail.
{

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 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 expired";
$mail->body = "This is the HTML message Body In bold!";
$mail->altbody = "The body in plain text for non-html mail clients";

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

";
echo "Mailer Error:". $mail->errorinfo;
Exit
}

echo "Message has been sent";
}

// }

Else
{
echo "Unsuccessful";
}

}


Mysql_close ();



?>





------Solution--------------------
The key is $address= $row [1];
Wrong
------Solution--------------------

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.