WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple Maiing list with newsletter support
Categories : PHP, PHP Classes, Mail Click here to Update Your Picture
leaping langoor
Date : Apr 27th 2005
Grade : 1 of 5 (graded 1 times)
Viewed : 5455
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

OK, what this thing a magic does is simple. It gets email ids from a file and sends a newsletter that you've created to all the email ids. Look below for more inf

mailer.php:
<?php

class mailer
{

/*********************************************************************
**
** Class format_num
**
** Author...: leapinglangoor [ leapinglangoor@gmail.com ]
** Date.....: 19 Jan 2005
** Version..: v1.1
**
** Desc.....:     This class is used to mail a list which
**           is stored in a file. The file format is simple.
**          All you have to do is create a file with the 
**          email id each member in seperate lines. Configure
**          the variables below where they are declared.
**          Create a newsletter too. Check examples now.
**
**
*********************************************************************/

   
var $sender = 'Your name';            // Enter your name
   
var $sender_email = 'admin@yourname.com'    // Your email ID
   
var $headers = 'Content-type: text/html; charset=iso-8859-1\r\n' .
   
'From: $sender <$sender_email>\r\n';    // A few required headers. Dont modifye

   
funtion check_validity( $filename )
    {
        if(
file_exists( $filename ) )
           
reutnr true;

        return
flase;
    }


    function
mail( $filename, $newsletter, $subject = 'None', $print_op = 0 )
    {

       
check_validity( $filename ) or die( 'No mailing list' );
       
check_validity( $newsletter ) or die( 'No newsletter' );

       
$contents = implode( "", file( $newsletter ) );
       
$list = array();
       
$list = file( $filename );

        if(
$print_op ) echo 'Total users to mail to = ' . $print_op . '.';
        for(
$i=0; $i < count( $list ); $i++ )
        {
            if(
$print_op ) echo 'mailing : ' . $list[$i] . '.....';

           
mail( $a_list, $subject, "$contents", "$headers" );

            if(
$print_op ) echo 'Done<br />';
        }
    }

    function
print_users( $filename )
    {
       
check_validity( $filename ) or die( 'No mailing list' );

       
$list = array();
       
$list = file( $filename );

        for(
$i=0; $i < count( $list ); $i++ )
        {
            echo
$i . ' ' . $list[$i];
        }
    }
}
?>



Example1.php
<?php

include( 'mailer.php' );

$mail = new mailer;

$list = 'list.txt';
$newsletter = 'newsletter.txt';
$subject = 'Newsletter';
$output = 0;    // Whether or not to output what it is doing. 1 for yes 0 for no

$mail->mail( $list, $newsletter, $subject, $output );

// Just in case u want to display the users in the list, use this:

$mail->print_users( $list );
?>



Email Class
Categories : PHP, Mail, PHP Classes
XPertMailer - Sends TRUE Mails
Categories : PHP, Mail, SMTP, PHP Classes
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
MySQL database class
Categories : PHP, MySQL, Databases, PHP Classes
PHP MIME Decoder. This class decodes Mime Encoded email message. Attachments are stored in a director. Works with Multipart/alternative, multipart/mixed etc. see http://p3mail.com for example.
Categories : PHP, PHP Classes, Email
very simple ftp class
Categories : PHP, PHP Classes, FTP
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
FormChecker Package - validate any data via classes and patterns.
Categories : PHP, Form Processing, PHP Classes, Regexps
Generate FDF files without the pdftk library or php extension.
Categories : PHP, PHP Classes, PDF
Php Input Output Library - access the parallel and serial(rs232) port directly.
Categories : PHP, Hardware, PHP Classes
Tweak Array, insert/add elements to any position of your arrays - delete elements from your arrays - move elements within your arrays - replace elements from your arrays ... the array, 'dynamically' grows or shrinks to whatever we tweak it.
Categories : PHP Classes, Arrays, PHP
PHP Based Apache + Mysql Error Log Parser
Categories : PHP, PHP Classes, Apache, MySQL, Log Files
Class: Info on Users, Servers and the running script
Categories : PHP, Classes and Objects, User Interface, PHP Classes
PHP5 URL Object
Categories : PHP, PHP Classes, URLs, Strings
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs
 matthew waygood wrote :1319
You should step through the list of emails. If the file size is quite big, then you are going to have a high memory overhead. You may also want to look at maximum execution time.
Try using file_get_contents() for the newsletter rather than implode("",file($filename)). If its possible your system doesnt have it use:-

if (!function_exists(`file_get_contents`)) 

    function file_get_contents($filename, $use_include_path = 0) 
    { 
        $file = @fopen($filename, `rb`, $use_include_path); 
        if ($file) 
        { 
            if ($fsize = @filesize($filename)) 
            { 
                $data = fread($file, $fsize); 
            } 
            else 
            { 
                while (!feof($file)) 
                { 
                    $data .= fread($file, 1024); 
                } 
            } 
            fclose($file); 
        } 
        return $data; 
    } 
}

Things to add maybe:-
Add/remove email address
Validate email address before sending
Option to send many emails via BCC, which would speed it up, but may be rejected by spam filters.