Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


sending bulk email with PHP

Posted on 2011-10-06
Medium Priority
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

Assisted Solution

Sid_F earned 500 total points
ID: 36923965
PHP is not the best way to send due to being picked up as spam but take a look at this post http://stackoverflow.com/questions/1118154/sending-mass-email-using-php
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36924126
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.

Author Comment

ID: 36924189
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Assisted Solution

by:Hugh McCurdy
Hugh McCurdy earned 500 total points
ID: 36924302
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: no-reply@your-domain.com" . "\r\n";

  $Sent = mail ( $Clean [ 'eMail' ], "Registration Confirmation", $Body, $Headers );

  return ( $Sent );

} // Send_eMail()

Open in new window

LVL 10

Accepted Solution

Derokorian earned 500 total points
ID: 36925492
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
ID: 36925555
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    http://code.google.com/a/apache-extras.org/p/phpmailer/
LVL 17

Assisted Solution

nanharbison earned 500 total points
ID: 36925768
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
ID: 36928698
try this phplist software , really it does what we want on bulk mailing


Author Closing Comment

ID: 36938042
thank you

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

580 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