Zend smtp mailJet template

297 views Asked by At

I'm trying to send email on my zend app Via mailjet. It works but cannot load the desired template. Code:

 $config = array('ssl' => 'ssl',
                'port' => 465,
                'auth' => 'login',
                'username' => 'mailjet api username',
                'password' => '8mailjet api key');


            $transport = new Zend_Mail_Transport_Smtp('in-v3.mailjet.com', $config);
            $mail = new Zend_Mail();
            $mail->addHeader('X-MJ-TemplateLanguage',true);
            $mail->addHeader('X-MJ-TemplateID','validationV2'); 
          // This is the template I wanna use.(above)
            $mail->setFrom('[email protected]', 'You');
            $mail->addTo('[email protected]', 'Anybody');
            $mail->setSubject('My first email by Mailjet');
            $mail->setBodyHtml('wxxxxxxxxxxxxxxxxxxxxxxxxx');

            $mail->send($transport);

If I could get any help woudl be great!

2

There are 2 answers

1
Zhivko On

You could try putting the numerical ID of the template in X-MJ-TemplateID. If it still doesn't work, file a support ticket

0
Biskuisec On

I encountered the same problem. It could be that Mailjet v3 for SMTP Relay is not Zend compatible.
However, the workaround I have tested is to use directly the Mailjet API after importing 'mailjet/mailjet-apiv3-php' via composer, like so :

    $mail = [
        'FromEmail' =>  '[email protected]',
        'FromName' => 'You',
        'To' => 'Anybody <[email protected]>,
        'MJ-TemplateID' => 1,
        'MJ-TemplateLanguage' => true
    ];

    $mj = new Client('mailjet api username', '8mailjet api key');
    $mj->post(Resources::$Email, ['body' => $mail]);

I'm curious what Mailjet's answer was for your support ticket, however!