Master! Master! Please come in and have a look! A feature for complex emails! Solution

Source: Internet
Author: User
Tags word wrap
Master !! Master !! Please come in and have a look !! A feature for complex emails !!! I have never worked out a task in a week. I still don't have any results when I work overtime this weekend. I hope I can give more advice when I first come into contact with the program !!!! Thank you !!! Requirement: create a contract module with multiple reminders. now I only have two reminders. That is, if sdate is detected, the edate must send an email at the same address as the current system time (). database setting: s master !! Master !! Please come in and have a look !! A feature for complex emails !!!
I have never worked out a task in a week. I still don't have any results when I work overtime this weekend. I hope I can give more advice when I first come into contact with the program !!!! Thank you !!!

Requirements:
Create a contract module with multiple reminders. now I only have two reminders.

That is:
If sdate is detected, the edate must send an email at the same time as the current system time.

Database settings:
Sdate edate email name
Adfd@aa.com adfd
Bbcc@aa.com bbcc

Xxbb@aa.com xxbb
Ccbb@aa.com ccbb



Basic implementation ideas:

I now use a phpmailer class. (Environment: linux + apache + php + mysql)

I wrote a cron. php file (as follows:) and used crontab to refresh the cron. php page once a day.

Determine if the current system time is the same as, and if the system time is the same, send an email.
According to the data above, we found that sdate contains two records:-19 and edate contains two records:-19. we have to send four emails to remind these four users.


Now my program has a problem: Only one of the records will be retrieved at a time, and only emails will be sent to this record, and the other three at the same time cannot reach the reminder function;

Very eager. please help me !!! Thank you very much !!



// The cron. php file is 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"; // The sdate and edate fields correspond to the two time ranges 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]) // currently, if the page is refreshed at a specified point, the program will only check the $ row [1], that is, the edate Time. only one email will be taken and sent. if there are two or more edates, no email will be sent. My goal is to: send an email if sdate or date is the same as the current time even if it is one hundred rows of data.
{

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 expired ";
$ 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 cocould not be 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.