PHP使用Outlook发送邮件

0sgqnhkj  于 2023-10-15  发布在  PHP
关注(0)|答案(3)|浏览(276)

有我的代码(它的Gmail帐户的作品,但不与Outlook)我改变主机,SMTP服务器(从0到2),端口(从465到587),但它不工作

$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();
polhcujo

polhcujo1#

**Outlook.com SMTP服务器地址:smtp-mail.outlook.com

试试你的主人。以及发送到Outlook邮件。我建议你浏览这个网站。网站包括SMTP端口、密码、服务器、SSL、地址。
https://www.lifewire.com/what-are-the-outlook-com-smtp-server-settings-1170671

jutyujz0

jutyujz02#

我只是更换了这条线,它的工作:

$mail->SMTPSecure = 'ssl';

这是:

$mail->SMTPSecure = 'tls';
e3bfsja2

e3bfsja23#

只是评论这一个://$mail->SMTPSecure = PHPMailer::ENGLISH_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}";
}

相关问题