Two questions for v4: setSender and setBody
Posted: Wed Mar 11, 2009 6:32 am
Hi Chris,
As I wrote in a previous thread, I'm converting my scripts from v3 to v4.
-----
setSender()
-----
In v3, I could use the following:
In v4, this doesn't work, the setSender() method only accepts an email address like so:
I've tried $message->setSender('delivery@domain.com' => 'Domain.com'); but that doesn't work. Is there anything I'm missing here or is it not possible to also include a name in the Sender header with v4?
----
setBody()
----
I'm trying to send a personalized email to one or more recipients. In v3, I used this (snipplet):
The $msg_tmpl is a simple email template, which has the variables #%recpname%# and #%recp_key%#. As you can see, for each recipient (email), the template gets called and the variables will be replaced with an actual recipient name and recipient key. Works perfectly.
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:
Thanks Chris!
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);
}