문제

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?

도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top