Jump to content

Using php for automatic emailing


ramonekalsaw

Recommended Posts

I have a php file containing a list of 365 quotes and a script for displaying them on my ExpressionEngine-based website. (This script was created by another developer.)

 

Now I need to be able to modify this script so it can automatically email a 'quote of the day' to my mailing list.

 

I'm trying to figure out the php code I need to be able to do this type of automatic mailing.

 

Can anyone offer any tips for getting this done?

 

Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/156465-using-php-for-automatic-emailing/
Share on other sites

You'll need something to execute the script each day, on UNIX you can use cronjobs, on Windows you can use scheduled tasks, or you can manually execute the mailer script each day.

 

First you need to select a quote from the list, you might want to use some sort of counter to ensure a quote doesn't get picked twice in one week or similar.

 

Other part of the script is to then loop through the mailing list to send the actual email with the quote.

 

Without seeing the format of the stored quotes, or the format of the mailing list we can't really help with the syntax.....

Off the top of my head, I would use a for loop that increments itself each time it is gone through.  Give each quote a corresponding id number, so the for loop can identify a quote given its unique id.  Then, using php's date function, assign each day a specific number:

 

Something like (and this is not complete)

1.Quote

2.Quote

 

if ($quote_num = date(z)) {

echo //corresponding quote;

}

 

What I don't know is how you are dividing up each quote, you must be able to identify them in the code.  Once you have that much, the date(z) function returns a number 0 through 365 corresponding to a day in the year.  So all day, until the date function turns over, your email will send that corresponding quote.  Hope this helps.

 

Oh yes, this only works if the script generating the code is executed by something the user does (i.e. navigate to this php page, etc.)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.