views:

63

answers:

1

Well, I'm trying to create a newsletter, that will send emails to users in a database. The newsletter itself would draw "events" and other activities from a database. Whats the best way to take that list, and put them in an email? I was thinking about putting them into an html page, then sending an html email, but not all emails support html(like school email). What would your guys recommend? Could you point me to some good resources?

Also, this is for a school project, so I cant use any open source type stuff, unfortunately :(

A: 

You are correct in your assumption that if you are creating html newsletters, you will also have to do a text based version for clients that don't support html or ones that ask to have e-mail be sent only in text. You will need to make sure your code sends both versions to recipients. You could also ask the recipients for their preference and send them the specific version that they requested.

For html e-mail it is highly recommended to read the following two articles by CampaignMonitor (they specialize in e-mail marketing sofware):

Note that I am assuming you are asking for help with the actual construction of the html for the email not the code needed to create and send the newsletter.

Good luck with your project.

==== UPDATE ====

So it seems that you actually need help in developing this project. Since this is a homework, I will provide some general advice that should steer you in the correct direction and get you started on the project. Then, if you have any specific problems with your code, you can ask about them on Stackoverflow.

There is really two things that need to be done here:

  1. In PHP, dynamically contruct a variable that contains the html or text versions of the e-mail that needs to be sent.
  2. Loop through your contact list and e-mail the contents of that variable.

Sending E-mail

I will start with the sending e-mail portion, because the links provide bellow also show you how to construct the message. Also, in your comment you said you already know how to contruct an html from a database. The following links show you two ways to send e-mail. You can either use the Mail function that comes with PHP or download the PEAR_Mail package. If you are allowed to use additional libraries and want to send html e-mail, I would recommend using the PEAR_Mail, because it makes things much easier if you want to send a both an html and text version of an e-mail together.

Note: To send an e-mail you will need to use some sort of mail server. If you are using Windows, you can install the SMTP service that comes with IIS or you can use an external smtp service such as google to send your e-mails.

Construct E-mail

The complexity here will depend on whether you just want a plain text e-mail or html. For either case you will need to read the event data from your database and add it to the message that you want to send.

Some Seudocode:

Loop through datarows
   message = DataRow[EventDate] + " " + DataRow[EventName] + "\n"

Loop through recipients 
   mail message

Hopefully this gives you a start. I would recommend getting php to send out an e-mail of a static html or text first. Once you have that code working you can start working on adding the functionality of reading event info from a database and sending it out.

Hope this helps.

Waleed Al-Balooshi
Awesome thanks! Thats really helpful! But I do need help creating and sending as well :'( I can form an html page by drawing various things from a db, I just dont know how to take that page, and put it into and email ...I guess I'll back track on my previous statement, if it makes it easier, and we can implement open source scripts and stuff, just not an entire install of something(Drupal, WP, etc).
jimmy
@jimmy Sorry it took me so long, but I have finally gotten a change to update my response. Hopefully it includes the information you are looking for.
Waleed Al-Balooshi