Page 1 of 1

news letter

Posted: Fri Jan 18, 2008 2:55 am
by sandeep.n
hi , i wanted to implement newsletter , can anybody guide me through it...

Re: news letter

Posted: Fri Jan 18, 2008 3:22 pm
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