Question

I'm using Swift Mailer to send emails to users. I've following script to send email to a number of users at a time.

$j=0;
while($row = mysql_fetch_assoc($email))
{
    $message[$j]->addTo($row['email_invited']);
    $mailer->send($message[$j]);
    $j++;
}

I get the following error while doing this:

Fatal error: Cannot use object of type Swift_Message as array in
/home/public_html/example.com/people.php on line 21

If I try to send emails like this:

while($row = mysql_fetch_assoc($email))
{
    $message->addTo($row['email_invited']);
}
$mailer->send($message);

It sends the email normally & every user gets it but the issue with that is every user can see what other users have got the email along with him. So basically in "To" field, every email is bound & thus every users gets to see all other email addresses. What I want to achieve is every user should get a personalized email only even though it's sent in bulk. That is why I tried to use array & separate email but getting error in that. Any idea how to achieve that?

Was it helpful?

Solution

How about doing. I think you need to create new instance of message (and maybe mailer too) in every loop.

while($row = mysql_fetch_assoc($email))
{
    $mailer = Swift_Mailer::newInstance($transportName);
    $message = Swift_Message::newInstance($subject);
    $message->addTo($row['email_invited']);
    $mailer->send($message);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top