SendMail & PHP [Debian 8 - PHP 7.0 - Laravel 5.2]

Tags: #<Tag:0x00007f63f361e668> #<Tag:0x00007f63f361e500> #<Tag:0x00007f63f361e3e8>

Bonjour à tous,
Voilà : j’ai développé un site internet, en local, sur du Windows, à coups de Wamp, avant de l’exporter sur une VM Jessie (Debian 8) qui l’héberge pour sa mise en production.

Cette VM est intégrée à un DOMAIN d’entreprise (Disons “@EXAMPLE.ledomain.mk”),
Et toutes les configurations du serveur ont été faites de façon à rendre mon site accessible sur ce domain par les utilisateurs.

Mon problème :
Mon site dispose de fonctions “mail” de PHP, pour notifier les Utilisateurs qui fonctionne bien en local (sur un Windows). (Après lui avoir renseigner le bon SMTP dans PHP.INI…).

En revanche, sur la Debian, rien ne se passe…

J’ai ajouté des tests, du genre :

<?php if(mail('mon_mail@example.ledomain.mk', 'sujet', 'message')) echo 'ok'; ?>

Qui me retourne “ok” + un email ‘sujet’ , ‘message’ sur mon_mail@example.ledomain.mk avec Windows,
Mais seulement “ok” sur ma Linux …

Toujours est-il que ce “ok” démontre que ma fonction mail tourne sans problème, mais que la gestion “SMTP” sur une Linux est différente, et c’est sur ce point que j’ai besoin de votre aide.

J’ai trouvé des débuts de pistes, comme quoi il faut installer le paquet “SendMail” (apt-get install sendmail),
Ajouter la ligne : sendmail_path = “/usr/sbin/sendmail -t -i” au php.ini de ma VM … Et … ?
Un regard sur “/var/log/mail.log” me montre que le mail ne rencontre pas de problème, il est accepté, “tout va bien” :

“Message accepted for delivery” (Je ne peux pas citer le message en entier)

Mon email ne semble pas avoir de problème mais rien n’arrive dans la boite destinataire (mon_mail@example.ledomain.mk) !!

Je précise que je ne passe pas par un SMTP de FAI, mais par un relais de l’entreprise que j’ai configuré ainsi :
Utilisant Laravel 5.2, j’ai renseigner le “.env” de mon application tel que :

MAIL_DRIVER=smtp
MAIL_HOST=null 
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Avec ça, le fichier /config/mail.php tel que :

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill",
    |            "ses", "sparkpost", "log"
    |
    */

    'driver' => env('MAIL_DRIVER', 'smtp'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Mailgun mail service which will provide reliable deliveries.
    |
    */

    'host' => env('MAIL_HOST', '10.x.x.x'), //Adresse IP de mon Serveur/Relais SMTP

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Port
    |--------------------------------------------------------------------------
    |
    | This is the SMTP port used by your application to deliver e-mails to
    | users of the application. Like the host we have set this value to
    | stay compatible with the Mailgun e-mail application by default.
    |
    */

    'port' => 25,

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => ['address' => 'mon_expediteur@example.ledomain.mk', 'name' => 'Expediteur'],

    /*
    |--------------------------------------------------------------------------
    | E-Mail Encryption Protocol
    |--------------------------------------------------------------------------
    |
    | Here you may specify the encryption protocol that should be used when
    | the application send e-mail messages. A sensible default using the
    | transport layer security protocol should provide great security.
    |
    */

    'encryption' => null,

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Username
    |--------------------------------------------------------------------------
    |
    | If your SMTP server requires a username for authentication, you should
    | set it here. This will get used to authenticate with your server on
    | connection. You may also set the "password" value below this one.
    |
    */

    'username' => null,

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Password
    |--------------------------------------------------------------------------
    |
    | Here you may set the password required by your SMTP server to send out
    | messages from your application. This will be given to the server on
    | connection so that the application will be able to send messages.
    |
    */

    'password' => null,

    /*
    |--------------------------------------------------------------------------
    | Sendmail System Path
    |--------------------------------------------------------------------------
    |
    | When using the "sendmail" driver to send e-mails, we will need to know
    | the path to where Sendmail lives on this server. A default path has
    | been provided here, which will work well on most of your systems.
    |
    */

    'sendmail' => '/usr/sbin/sendmail -bs', //Dois-je le changer pour : "/usr/sbin/sendmail -t -i" ?

];

Lorsque je pourris ces fichiers de configuration (Je mets un IP faux, …), mes mails locaux (Sur le Windows) passent tranquillement…
J’en conclu que c’est avant tout et surtout le fichier PHP.ini qui dirige cet envois ^^ :

Le fichier php.ini, j’en ai trouvé plusieurs dans ma VM … Je les ait tous configurés tels que celui de Wamp sur mon Windows (avec le Path en +) soit :

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = 10.100.0.35
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from ="mon_expediteur@example.ledomain.mk"

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "/usr/sbin/sendmail -t -i"

Dans différents tutos, j’ai trouvé des choses telles que l’ajout d’un paquet “sendmail-cf” qui offre ses propres fichiers de configuration…
J’ai bien essayé de l’ajouter mais aucun de mes essais ne solutionne mon problème … !
J’en arrive à ne plus savoir ni où ni quoi modifier pour que ma Debian daigne envoyer des emails …
Des idées pour m’éclairer ??

RÉSOLUS : On oublis, pardon, j’ai posté un peu vite… Je suis passé de sendmail à postfix et tout fonctionne niquel !
J’aurais bien supprimé mon poste mais on ne peut pas le faire…