news letter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sandeep.n
Forum Newbie
Posts: 5
Joined: Wed Jan 16, 2008 11:03 pm

news letter

Post by sandeep.n »

hi , i wanted to implement newsletter , can anybody guide me through it...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: news letter

Post by Jonah Bron »

Firstly, you would need to send run the page one a week, or month, or however often it will be sent. This is because php cannot exicute itself. Now, you will need to create the newsletter to be sent, and save it as, for example, "newsletter.html", and another file that contains the email addresses of all your recipients, as "recipients.html", that looks like this:

Code: Select all

someone@domain.com
someone_else@other_domain.com
blah@somesite.com
etc.

The "newsletter.html" file will be updated by you every time you send it.

Then, use something like this to send it to each of your receivers:

Code: Select all

 
<?php
$receivers = file_get_contents('recipients.html');//get the emails
$newsletter = file_get_contents('newsletter.html');//get the newsletter to send
$receivers = explode('
', $receivers);//break up receivers into array
$headers = 'MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1';//make email HTML
 
foreach ($receivers as $receiver){//run through each receiver,
    if (mail($receiver, 'the subject of the newsletter', $newsletter, $headers){
        echo 'Email sent to '. $receiver .'<br />';
    }else{
        echo 'Not sent to '. $receiver .'<br />';
    }
}
Now, open this in your browser once a week, after updating newsletter.html, and it will output something like this:

Email sent to someone@domain.com
Email sent to someone_else@other_domain.com
Email sent to blah@somesite.com
Post Reply