Omar Krichen
Omar Krichen

Reputation: 163

PHP Sending mail with Outlook

there is my code (it's works for gmail account but not with outlook) I change Host, SMTPDebug(from 0 to 2),Port(from 465 to 587) but it doesn't work

    $mailto = $mail;
    $mailSub = "Invitation";
    $mailMsg = "Bonjour $nom  $prenom de cin: $CIN, <br> Votre entretien est 
    le $date à $heure <br> Merci d'être à l heure <br> Cordialement ";
    require '../PHPMailer-master/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    $mail->IsSmtp();
    $mail->SMTPDebug = 2;

    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'ssl';
    $mail->Host = "smtp.live.com";
    $mail->Port = 587; 

    $mail->IsHTML(true);
    $mail->Username = "*******@******";
    $mail->Password = "*********";
    $mail->setFrom("*****@******");
    $mail->Subject = $mailSub;
    $mail->Body = $mailMsg;
    $mail->AddAddress($mailto);
    $mail->Send();

Upvotes: 5

Views: 29245

Answers (3)

moez cherif
moez cherif

Reputation: 101

Juste comment this one : //$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;

     //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER; 
    $mail->isSMTP();          
                                     
    $mail->Host       = 'smtp.office365.com'; 
    $mail->SMTPAuth   = true;         
    $mail->Username   = '[email protected]';                     //SMTP username
    $mail->Password   = 'xxxxxxxxx';                               //SMTP password
    //$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
    $mail->Port       = 587;                                      //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     //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 = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</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 "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

Upvotes: 0

Nauman Moazzam
Nauman Moazzam

Reputation: 158

Outlook.com SMTP server address: smtp-mail.outlook.com

Try this with your host. And for sending to outlook mails. I suggest you go through this website. Website includes ports to SMTP, password, server, SSL, address.

https://www.lifewire.com/what-are-the-outlook-com-smtp-server-settings-1170671

Upvotes: 9

Omar Krichen
Omar Krichen

Reputation: 163

i just replaced this line and it's worked:

      $mail->SMTPSecure = 'ssl';

to this:

      $mail->SMTPSecure = 'tls';

Upvotes: 3

Related Questions