AC
AC

Reputation:

Send emails to multiple users using PHP/Javascript

I was trying to find an easier way to send e-mails to all my clients using our database (MySQL). I wanted to see if there is a way that it can select all the e-mails of my clients and I can add message, Subject and send it to all of my clients from my website rather than copying each of the mail.

Is there a way to integrate SMTP to do this? either using PHP or javascript.

Thanks.

Upvotes: 0

Views: 1417

Answers (2)

karim79
karim79

Reputation: 342665

Yes, there are about 5,247 ways. See these:

Those are all good (and not the only ones). It is up to you to pick the one that best suits your purpose, there is no "single best" library.

Upvotes: 3

TigerTiger
TigerTiger

Reputation: 10806

I use SwiftMailer .. it works wonders for me.

*  Send emails using SMTP, sendmail, postfix or a custom Transport implementation of your own
* Support servers that require username & password and/or encryption
* Protect from header injection attacks without stripping request data content
* Send MIME compliant HTML/multipart emails
* Use event-driven plugins to customize the library
* Handle large attachments and inline/embedded images with low memory use



require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('[email protected]' => 'John Doe'))
  ->setTo(array('[email protected]', '[email protected]' => 'A name'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$numSent = $mailer->batchSend($message);

printf("Sent %d messages\n", $numSent);

/* Note that often that only the boolean equivalent of the
   return value is of concern (zero indicates FALSE)

if ($mailer->batchSend($message))
{
  echo "Sent\n";
}
else
{
  echo "Failed\n";
}

read more here .. http://swiftmailer.org/docs/batchsend-method

Upvotes: 0

Related Questions