1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public function send_messageTest(){
if(isset($this->emailtest)){
if(empty($this->emailtest)){
}elseif(magixcjquery_filter_isVar::isMail($this->emailtest) == false){
// message d'erreur
}else{
$db = sn_db_message::adminDbMsg()->select_for_edit_message($this->send);
$count = 0;
//Create the Transport
$transport = Swift_MailTransport::newInstance();
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Use AntiFlood to re-connect after 100 emails specify a time in seconds to pause for (30 secs)
$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100, 30));
$lotsOfRecipients = array($this->emailtest);
$numSent = null;
//Continue sending as normal
foreach ($lotsOfRecipients as $recipient){
//Create a message
$message = Swift_Message::newInstance();
//Or set it after like this
$message->setSubject($db['subject']);
$message->setFrom(array($this->emailtest));
$message->setTo($recipient);
//Pass it as a parameter when you create the message
$message->setBody($db['content'],'text/html');
//Add alternative parts with addPart()
$message->addPart($db['content'], 'text/plain');
//Send the message
$numSent .= $mailer->batchSend($message);
//print ($recipient);
$count++;
}
printf("Sent %d messages\n", $count);
/* Note that often that only the boolean equivalent of the
return value is of concern (zero indicates FALSE)
*/
/*if ($numSent)
{
echo "Sent\n";
}
else
{
echo "Failed\n";
}*/
}
}
} |
Partager