How to Send a Mass PHP Email
There are a number of different reasons you might need to send an email to a large number of people. Perhaps you run a small business or a club and need to send newsletters, special event notices or invitations to your customers or members.
With Microsoft Outlook and online email services such as Gmail, your ability to send mass emails is limited. Many versions of Outlook limit emails to approximately 100 recipients, and Google will temporarily disable your account if you send messages to more than 500 recipients per day.
Instead, you can use the popular computer scripting language PHP to accomplish your goals. Select one of the open source PHP code libraries that are freely available. The most widely used code libraries are phpList, PHPMailer and SwiftMailer.
Instructions
-
phpList
-
1
Make sure you have access to your website's hosting account. You must also verify that PHP is installed and available on the server on which your account is running.
-
2
Download the latest stable release from the phpList website and unpack the directories and files from the archive. Upload the directories and files to a directory on your web server that is accessible via the web, and create a database for phpList to use. Use a web browser to navigate to the "lists/admin" sub-directory where you uploaded the files to complete the installation.
-
-
3
For phpList, log in to the admin section and create a list of the individual email addresses to which you want to send your message. Click the "Send a message" menu item and prepare the actual email. When you are satisfied with the message, click the "Send" button.
PHPMailer
-
4
Make sure you have access to your website's hosting account. You must also verify that PHP is installed and available on the server on which your account is running.
-
5
Download the PHPMailer package from the PHPMailer website and extract the "class.phpmailer.php" and "languages/phpmailer.lang-en.php" files. Upload these files to the working directory on your web server. Note that PHPMailer does not have a graphical user interface, so you'll need to call the class directly in another PHP script.
-
6
Draft a PHP script that includes the class.phpmailer.php file ("require("class.phpmailer.php");"), then create a new object from the PHPMailer() class ("$mail = new PHPMailer();"). Use "$mail->From", "$mail->AddAddress" and "$mail->Body" to prepare the message within the script. Use "$return = $mail->Send()" at the end of the script to send the message.
SwiftMailer
-
7
Make sure you have access to your website's hosting account. You must also verify that PHP is installed and available on the server on which your account is running.
-
8
Download the most recent package of SwiftMailer from the SwiftMailer website, and extract the files. Upload all of the files from the "lib/" directory to your web host. Again, note that SwiftMailer is a class that you call in another PHP script in order to send mass emails.
-
9
Write a new PHP script that includes the swift_required.php file ("require_once 'lib/swift_required.php';"), and calls the newInstance() method of Swift_Message ("$message = Swift_Message::newInstance()"). Use the "setFrom()", "setTo()" and "setBody()" methods to prepare the message itself. To send the message create a transport, create an instance of Swift_Mailer using the transport you created and use the send() or batchSend() methods on that object.
-
1
Tips & Warnings
Avoid using only the default mail() function that's built into PHP. Although you could write your own PHP mass email application from scratch by using the mail() function, that function can be a significant drain on your computing resources because it opens and closes an SMTP connection for each email. In addition, it can be difficult to properly throttle the pace at which your emails are sent, which increases the likelihood that the receiving mail server will flag your message as spam.
Be sure that every recipient to each of your mass emails has agreed to be on your mailing list, and promptly remove anyone who requests to no longer receive your correspondence.
References
Resources
- Photo Credit global technology image by patrimonio designs from Fotolia.com