sending bulk email with PHP

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PHP is not the best way to send due to being picked up as spam but take a look at this post
Hugh McCurdyCommented:
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.
BRMarketingAuthor Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Hugh McCurdyCommented:
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

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hugh McCurdyCommented:
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
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.
Loganathan NatarajanLAMP DeveloperCommented:
try this phplist software , really it does what we want on bulk mailing
BRMarketingAuthor Commented:
thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.