Having difficulty including mailwizz with laravel 5.2

BirdyUK

Member
Hi all,

As a newbie to the laravel framework im having a bit of difficulty indlucing mailwizz sdk with laravels framework.

Ive tried to create a model and call the model from a controller but i think the issue lays with including the autoloader from the sdk.

Is anyone here running mailwizz with a laravel install and if so could you lend a helping hand on how to get the correct files included without messing with the laravel installation.

Is there a simple process i could take?

Cheers all.
 
Ive got it working now but not sure just how good or secure my model is that im calling. Here is my noob laravel approach!

ive created a mode and placed the mailwizz sdk files into a mailwizz folder within the models folder so the scructure is as follows:

Laravel Install >> App >> Models >> Mailwizz
  • Mailwizz.php (Contains my mailwizz list id, custom fields and default mailwizz code)
  • setup.php (Downloaded from githib, Contains mailwizz api keys)
  • MailWizzApi (Folder downloaded from github, Contains the autoloader ect ect..)

My Mailwizz Model is as follows:

Code:
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use MailWizzApi_Autoloader;
use MailWizzApi_Endpoint_ListSubscribers;


class MailWizzModel extends Model
{
    public function sendMailwizz($emailAddress, $firstName, $lastName)
    {
        require_once dirname(__FILE__) . '/mailwizz/setup.php';
          $listUid    = '-- REMOVED LIST ID --';
          $endpoint   = new MailWizzApi_Endpoint_ListSubscribers();
          $response   = $endpoint->create($listUid, array(
              'EMAIL' => $emailAddress,
              'FNAME' => $firstName,
              'LNAME' => $lastName
          ));
          $response   = $response->body;
    }
}

in my controller i call the MailWizzModel... And then call the functions by passing in the 3 values such as email, firstname, lastname.. I have several more custom fields but not required for this demo purpose.

Code:
        $sm = new MailWizzModel;
        $sm->sendMailwizz($emailAddress, $firstName, $lastName);
        return $sm;

Hopefully this will help anyone else who has questions in regards to including mailwizz with laravel, im sorry for the very poor layout and explaination, I dont have the time to write a decent article at the moment and this is mainly just to show @twisted1919 what my markup is like.

If anyone is curious at any stage and has any issues with laravel feel free to ask me and ill do what i can to help.
 
Looks very decent to me, the require_once call to setup.php file makes sure the autoloader is included only once, so you dodged a nasty bullet with that ;)
 
@twisted1919, The only issue i have is the ' $response = $response->body; ' is returning an empty array with no response object to indicate if there was an error or if it was successful. Would i need to manually add a callback function to either catch an exception if one occurs or send back a success message if the request status returns a 200? I understand your busy mate so its not massivly important just curious if there is something ive missed.

mailwizz.jpg


Cheers
 
@twisted1919 - I have tried both print_r and echo but both still return the empty array. In terms of error reporting i have it enabled both in php and in laravels standard .env file so its a strange one as its throwing no error and an empty array as if nothing has worked but the record actually gets inserted into mailwizz, it just doesnt send back any success message or failure for that matter if the email address already exists for example.

i might just hard code a callback function for on success but its strange how the $response->body wont display anything other than [ ]
:confused:

Cheers
 
@twisted1919 - I have a template theme i need to carry through to mailwizz but the template its self is 99% dynamically generated, including css and styles, all of the styling is coming from inline.

For example: I have a template that is sent as part of a autoresponder campaign, The tempalte contains bidds from users such as pricing and general info but then also the users profile badges like, Recommended, Approved, Country Flag and more..

So having a static template in MW with dynamic tags or fields wont work correctly as i need to be able to include things like this for different bidders within the template as we list approx 8 bidders per email and each bidder has different profile badges and stats:

Code:
<span style="background-color:#5f9218;border-radius:3px;font-size:9px;line-height:9px;color:#ffffff;font-weight:bold;padding:5px 4px 3px 4px;white-space:nowrap;vertical-align:middle;display:inline-block;">APPROVED</span>

That not all the bidding users will have, Some might be approved sellers and some might not, Some might have other badges that others might not ect ect..

What would you say is the best bet? I was thinking of using transaction emails with file_get_contents and dynamically generate the template server side, assign the filename to a variable and then do an ajax request to the api with the subscribers details and the file name.

Not sure what the best approach would be on this as its already part of a AR campaign? Possible solutions?

Cheers.
 
What would you say is the best bet? I was thinking of using transaction emails with file_get_contents and dynamically generate the template server side, assign the filename to a variable and then do an ajax request to the api with the subscribers details and the file name.
Have you actually tried with this one ?
 
Back
Top