I want to send an email via my localhost PHP after a specific action is completed.
In the given code, I am testing emails statically to check if it works.
I tried this code:
<?php
require_once "../../../vendor/autoload.php";
use MailjetResources;
//passed in my actual api keys
$mj = new MailjetClient('api_key','secret_key',false,['version' => 'v3.1']);
$body = [
'Messages' => [
[
'From' => [
'Email' => "[email protected]",
'Name' => "name"
],
'To' => [
[
'Email' => "[email protected]",
'Name' => "name"
]
],
'Subject' => "Hello from Mailjet",
'TextPart' => "Greetings from Mailjet!",
]
]
];
try {
if( $mj->post(Resources::$Email, ['body' => $body])){
echo "Email sent successfully!";
}else{
echo "Email doesnt sent!";
}
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."n";
}
?>
It’s returning : Email sent successfully!
but, in reality, nothing has been sent.