0

I'm currently working on a contact form page. I would like to use mailjet services unfortunately, mail does not send.

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;

define('MJ_APIKEY_PUBLIC', 'xxx');
define('MJ_APIKEY_PRIVATE', 'xxx');

$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3.1']);


$action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);

switch ($action){

    case 'envoyerMessage':

        $mail = filter_input(INPUT_POST, 'mail', FILTER_SANITIZE_STRING);
        $message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING);



        $body = [
            'Messages' => [
                [
                    'From' => [
                        'Email' => "$mail",
                        'Name' => "Mailjet Pilot"
                    ],
                    'To' => [
                        [
                            'Email' => "xxx",
                            'Name' => "passenger 1"
                        ]
                    ],
                    'Subject' => "Your email flight plan!",
                    'TextPart' => "$message"
                ]
            ]
        ];
        $response = $mj->post(Resources::$Email, ['body' => $body]);
        $response->success() && var_dump($response->getData());


        addASuccess('Merci, votre message a bien été pris en compte.');
        include 'views/v_success.php';
        include 'views/v_support.php';


        break;

    default:
        include 'views/v_support.php';
        break;

}

Here is my code ^^^^

When I try the code on the support page, mail does not send but I got the success message. Is that normal ?

HyperVince
  • 13
  • 1
  • That you _get_ a success message in any case, if you are not making the output of your success message dependent on _anything_ - yes, that is pretty normal. – CBroe Jul 06 '22 at 07:58
  • `$response->success() && var_dump($response->getData());` - if `$response->success()` does not return true, then PHP short-circuits the evaluation of this expression, and the var_dump will never execute. – CBroe Jul 06 '22 at 08:00

0 Answers0