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.
My CODE
<?php
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.mysite.net', 25)
->setUsername('me@mysite.net')
->setPassword('me123456')
;
$transport = Swift_MailTransport::newInstance();
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('me@mysite.net' => 'My Name'))
->setTo(array('name1@mysite.net', 'name2@mysite.net'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
?>
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.