Envoi de mail en PHP

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Envoi de mail en PHP

Re: Envoi de mail en PHP

par @rthur » 28 mai 2019, 09:19

Voici un exemple fonctionnel avec Office365 et PHPmailer :
https://stackoverflow.com/a/41592622

Envoi de mail en PHP

par parfait » 28 mai 2019, 06:54

Bonjour, j'ai un souci avec mon hebergement mutualié en fait la fonction mail() est apparement bloquée ( ne fonctionne pas) on m'a conseiller PHPMailler mais je n'y arrive pas
J'ai un email professionnel sur Office 365 et suis hebergé chez Goddady serveur windows PLESK
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.office365.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'Mon email';                 // SMTP username
    $mail->Password = '*******!';                           // SMTP password
    //$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    //$mail->SMTPSecure = 'ssl';
    $mail->SMTPSecure = 'starttls';
    $mail->Port = 587;                                    // TCP port to connect to
    
    //Recipients
    $mail->setFrom('[email protected]', 'Moi');
    $mail->addAddress('[email protected]', 'Lui');     // Add a recipient
    $mail->addAddress('[email protected]');               // Name is optional
    //$mail->addReplyTo('[email protected]', 'Information');
    //$mail->addCC('[email protected]');
    //$mail->addBCC('[email protected]');

    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Pour tester mes messages';
    $mail->Body    = 'Mon petit sa vas?? <br> Suis à la ligne <b>Cool<b>';
    //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Erreur.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
J'ai cette erreur :
2019-05-28 04:49:11 SMTP ERROR: Failed to connect to server: An attempt was made to access a socket in a way forbidden by its access permissions. (10013)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Erreur.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Merci de m'aider