sending bulk email with PHP

Posted on 2011-10-06
Last Modified: 2012-05-12
do you know how to send emails with PHP?
I want to use "do while" to send emails to the all email addresses at my table.
Do you have a sample code?
Question by:Braveheartli
    LVL 5

    Assisted Solution

    PHP is not the best way to send due to being picked up as spam but take a look at this post
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    I have code that I've written that works (but is specific to my application).  It is meant for one e-mail at a time (confirming registration).  It won't work well for bulk mail.

    Can you share more of what you are trying to do?  Context helps.
    LVL 1

    Author Comment

    Dear hccurdy,
    I have a table which has more than 1000 email address.
    I want to send email one by one to let my users know about membership details.
    It should work like "do while loop" start from the first email address to send until  the last email record.
    thank you
    LVL 13

    Assisted Solution

    by:Hugh McCurdy
    I can help you with code but Sid makes a good point about bulk mail.

    Here's some sample code that sends one e-mail and is working.  You'll need to modify it to meet your needs (for instance, change your-domain to your actual domain).  You can put the function call inside your loop.
    (It might not be the best code ever written but it is working.)

    function Send_eMail ( $Clean, $ActivationCode, $CompanyKey, $CompanyEmail )
      $ActivateURL = sprintf ( "http://%s%s/%s?company=%s&guest=%s&activation=%s",
                getenv ( 'HTTP_HOST' ), HomeFolder(), "login.php", $CompanyKey, $Clean [ 'eMail' ], $ActivationCode );
      $Body =       "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n" .
                "<html>\n" .
                "<head>\n" .
                "</head>\n" .
                "<body>\n" .
                "This message was sent to " . $Clean [ 'eMail' ] . "<br /><br />\n" .
                "Thank you for beginning the registration process.<br /><br />\n" .
                "Your activation code is --  " . $ActivationCode . "<br /><br />\n" .
                "The next step is to activate your account.<br /><br />\n" .
                "Either <a href='" . $ActivateURL . "'>" .  "click here" . "</a>\n" .
                "or enter your activation code to the web page shown after you registered<br /><br />\n" .
                "If you did not request this message, please delete it.<br />\n" .
                "</body>\n" .
                "</html>\n" ;
      $Headers = "MIME-Version: 1.0" . "\r\n";
      $Headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
      $Headers .= "From:" . "\r\n";
      $Sent = mail ( $Clean [ 'eMail' ], "Registration Confirmation", $Body, $Headers );
      return ( $Sent );
    } // Send_eMail()

    Open in new window

    LVL 10

    Accepted Solution

    You should take a look at the PHP-Mailer class as this will allow you to use authenticated email servers (works with gmail, for example).

    This is what I use to send mail to my members, helps prevent going into spam because its from a recognized / trusted host. And also IIRC has functionality built for mass mailings. If it doesn't you can use a loop as previously suggested, tho I would recommend using a sleep command every 5-10 iterations of the loop to prevent hang ups with the mail server.
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    I posted code because that's what I was asked to do.  

    Still, I think Sid and Kerokorian have good advice.  I think the PHP-Mailer class is a good idea even though I haven't seen it yet.  (I'm going to go look it up now.)  Seems to be several.  I'm going to investigate this one when I get a chance
    LVL 17

    Assisted Solution

    Sending PHP email is tricky. Businesses that have an email server set up sometimes reject some PHP email , you can't be sure everyone will get it. You would be better off using Constant Contact or another email marketing website, which ensure the emails will be sent and allows you to track what percent of recipients opened the email, or deleted it, and the percent of times it was delivered as spam.
    You are also required by law to have an unsubscribe option for recipients, which email marketing websites always provide.
    You can upload spreadsheets of email addresses, so you don't have to enter them one at a time.
    LVL 36

    Expert Comment

    by:Loganathan Natarajan
    try this phplist software , really it does what we want on bulk mailing
    LVL 1

    Author Closing Comment

    thank you

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    Preface In the first article: A Better Website Login System ( I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now