Created
January 17, 2017 14:12
-
-
Save dewwwald/b5ba9802d87af9801c7f45d663a86eae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Jobs; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Mailchimp; | |
use Mail; | |
use Log; | |
use App\Models\User; | |
class SubscribeToMailchimp implements ShouldQueue | |
{ | |
use InteractsWithQueue, Queueable, SerializesModels; | |
protected $user; | |
public $mailchimp; | |
public $listId = 'yourid'; | |
/** | |
* Create a new job instance. | |
* | |
* @return void | |
*/ | |
public function __construct(User $user, Mailchimp $mailchimp) | |
{ | |
$this->user = $user; | |
$this->mailchimp = $mailchimp; | |
} | |
/** | |
* Execute the job. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
try { | |
$this->mailchimp | |
->lists | |
->subscribe( | |
$this->listId, | |
['email' => $this->user->email], | |
[ | |
'FNAME' => $this->user->first_name, | |
'LNAME' => $this->user->last_name, | |
'MMERGE3' => $this->user->profile->country ? $this->user->profile->country->country : '' | |
] | |
); | |
} | |
catch (\Mailchimp_List_AlreadySubscribed $e) | |
{ | |
$content = 'The user '.$this->user->email.' has already subscribed {first_name: '.$this->user->first_name.', last_name: '.$this->user->last_name; | |
Log::error($content); | |
} | |
catch (\Mailchimp_Error $e) | |
{ | |
$content = 'The user '.$this->user->email.' had an issue subscribing<br>'; | |
$content .= $this->user->first_name."<br>"; | |
$content .= $this->user->last_name."<br>"; | |
$content .= $this->user->profile->country->country."<br>{"; | |
$content .= $e."}"; | |
Log::error($content); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
1.Possible to send email without List_ID..?
2.How to send mail into particular Email...?
Thanks