I have problem with sending mails with different attachments for each email adress. Need to doing it in loop with 20 email batch. All mails i have in db with send attempts. In loop 1st mail sends correcly and i receive it. But after sending 1st mail i get blank page and script stops.
I'm using Kohana framework and Gmail. All messages, attachments, addresses are preparing correcly. Any ideas?

Here is my code:
Code: Select all
public function send()
{
if ( ! Auth::instance()->logged_in('admin'))
{
// User is not admin.
url::redirect('auth/logged_in');
}
$swift = email::connect();
$email_templates_model = new Email_Templates_Model;
$templates = $email_templates_model->getTemplate();
$emails_model = new Emails_Model;
$emails_to_send = $emails_model->getEmail();
$templates = $templates->result_array(FALSE);
$from = 'test@gmail.com';
foreach($emails_to_send as $id => $email)
{
echo $id;
$subject = $id.$templates[$email->template_id - 1]['subject'];
$body = $id.$templates[$email->template_id - 1]['body'];
// Adresaci
$recipients = new Swift_RecipientList;
$recipients->addTo($email->email);
// Build the HTML message
$message = new Swift_Message($subject, $body, "text/html");
$message->setEncoding("utf8-general-ci");
// Attachment
$swiftfile = new Swift_File('attached/'.date('Y-n-j').'/'.$email->file);
$attachment = new Swift_Message_Attachment($swiftfile);
$message->attach($attachment);
$body = new Swift_Message_Part($body, "text/html");
$body->setEncoding("utf8-general-ci");
$message->attach($body);
$swift->send($message, $recipients, $from);
}
$swift->disconnect();