As I wrote in a previous thread, I'm converting my scripts from v3 to v4.
-----
setSender()
-----
In v3, I could use the following:
Code: Select all
$message->headers->set('Sender', 'Domain.com <delivery@domain.com>');Code: Select all
$message->setSender('delivery@domain.com');----
setBody()
----
I'm trying to send a personalized email to one or more recipients. In v3, I used this (snipplet):
Code: Select all
for($i=0;$i<$nr_recipients;$i++) {
$e_msg = str_replace(array('#%recpname%#','#%recp_key%#'),array($_POST['recpname'][$i],$recp_key_arr[$i]),$msg_tmpl);
$message->setBody($e_msg);
$email_sent = $mailer->send($message,new Swift_Address($_POST['recpemail'][$i],$_POST['recpname'][$i]),new Swift_Address($senderemail,$sendername));
}
In v4, I'm trying to do the same, but somehow, it always uses the body for the first recipient..it doesn't replace it. Please note that I've made sure that $e_msg has the correct content. I echo'ed it inside the for loop and it is being personalized correctly. So, it looks like setBody doesn't replace the initial body when you call it again?
snipplet for v4:
Code: Select all
$message->setFrom(array($senderemail => $sendername));
for($i=0;$i<$nr_recipients;$i++) {
$e_msg = str_replace(array('#%recpname%#','#%recp_key%#'),array($_POST['recpname'][$i],$recp_key_arr[$i]),$msg_tmpl);
echo $e_msg.'<br /><br />';
$message->setBody($e_msg,'text/plain');
$message->setTo(array($_POST['recpemail'][$i] => $_POST['recpname'][$i]));
$email_sent = $mailer->send($message);
}