I haven't been able to get this to work yet... It runs through, doesn't give any errors, but on the $mailer->batchSend($message) part it returns 0 every time.
Code: Select all
require_once 'lib/swift_required.php';
$emails = $this->get_recipients($emails);
$transport = Swift_SmtpTransport::newInstance('smtpserver', 587)
->setUsername('user')
->setPassword('pass');
$mailer = Swift_Mailer::newInstance($transport);
$replacements = $this->build_replacements($email, $id, $template_id);
$decorator = new Swift_Plugins_DecoratorPlugin($replacements);
$mailer->registerPlugin($decorator);
$message = Swift_Message::newInstance($subject, 'text/html')
->setFrom(array('sentfrom' => 'aname'))
->setTo($emails)
->setBody($message);
$numSent = $mailer->batchSend($message);
echo 'Sent: '.$numSent;
That's what my code is looking like so far, some calls are to my own functions, but they should be passing back the kind of arrays you've documented above. I took out some things like the SMTP, username and password just so the whole world doesn't see them.
Yeah, it's kind of a mess, I've been re-arranging stuff for a while and re-writing some of my old functions since I moved from version 3 to 4.
******** EDIT ********
Nevermind that... I went back to some of my other code and found out that it wasn't passing the recipient list back correctly. Now it's sending out to people, but it was a blank email. I'll continue to mess around with it and see if I can figure anything out.
**** EDIT ****
Well, got it all working. It really wasn't anything on swift mailers end, it was all my side when I converted things over I either didn't get some POST values correct or just messed something up. I noticed my ->setBody($message) was wrong, $message is what I used to initialize the Swift_Message, but it was also a variable I was passing to my function for the body, so that was a fail.