Take the 2-minute tour ×

I am using swift-mailer to send email to user. I have implemented it and it works well. But I have different body for different mails, ie i need to include the ID, Name , address in the mail which is taken from the database. I was thinking of using a loop for this. But many of article shows its not a good practice to send the mail in loop. I use this helpful tutorial as reference. Is there any better way for this, If loop is to be used how could i implement this. I dont have much experience in php, I am basically a jsp developer.


require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.mysite.net', 25)


$transport = Swift_MailTransport::newInstance();

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

// Create a message
->setFrom(array('me@mysite.net' => 'My Name'))
->setTo(array('name1@mysite.net', 'name2@mysite.net'))
->setBody('Here is the message itself')

// Send the message

share|improve this question
add comment

1 Answer

up vote -1 down vote accepted

Sending email in a loop is not a good practice, because you could be treated as a spammer by your SMTP provider. You should have a look into Decorator plugin for Swift mailer.

share|improve this answer
isnt decorator plugin also sending it in a loop? a single email for every recipient? –  Gigala Jan 23 '13 at 8:49
You're right Gigala. Decorator plugin will also send multiple emails. As a workaround to SMTP restrictions, there are also AntiFlood or Throtter plugins. –  Guillaume Poussel Jan 23 '13 at 17:41
add comment

Your Answer


