Using Mailjet wrapper for Laravel to send mails using their API service
You can read more on this in my Medium blog post here. Do let me know your thoughts through comments or through mail [email protected]
Have a good day !
Using Mailjet wrapper for Laravel to send mails using their API service
You can read more on this in my Medium blog post here. Do let me know your thoughts through comments or through mail [email protected]
Have a good day !
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Validator; | |
use Mailjet\LaravelMailjet\Facades\Mailjet; | |
use Mailjet\Resources; | |
class EnquiryController extends Controller | |
{ | |
public function index(Request $request) | |
{ | |
$input = $request->all(); | |
Validator::make($input, [ | |
'name' => [ | |
'required', | |
'string', | |
], | |
'email' => [ | |
'required', | |
'string', | |
'email', | |
'max:255', | |
], | |
'phone' => [ | |
'required', | |
'digits:10', | |
'max:10', | |
], | |
])->validate(); | |
$formdata = $request->except('_token'); | |
$mj = Mailjet::getClient(); | |
$body = [ | |
'FromEmail' => "[email protected]", | |
'FromName' => "From name to be displayed in Inbox", | |
'Subject' => "New Website Enquiry", | |
'MJ-TemplateID' => 123456789, | |
'MJ-TemplateLanguage' => true, | |
'Vars' => json_decode(json_encode($formdata), true), | |
'Recipients' => [['Email' => "[email protected]"]] | |
]; | |
$response = $mj->post(Resources::$Email, ['body' => $body]); | |
if($response->success()){ | |
- do success event callback - | |
} else { | |
- do failure event callback - | |
} | |
} | |
} |