PHP

[PHP] SMTP 전송을 이용한 이메일 발송(office365)

chsr 2022. 1. 27. 14:42
728x90
반응형

■ PHP SMTP 전송을 이용한 이메일 발송, mail smtp (office365)


 사용법

<?php
    require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'smtp.office365.com';
    $mail->Port       = 587;
    $mail->SMTPSecure = 'tls';
    $mail->SMTPAuth   = true;
    $mail->Username = 'somebody@somewhere.com';
    $mail->Password = 'YourOffice365Password';
    $mail->SetFrom('somebody@somewhere.com', 'FromEmail');
    $mail->addAddress('recipient@domain.com', 'ToEmail');
    //$mail->SMTPDebug  = 3;
    //$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; 
    //$mail->Debugoutput = 'echo';
    $mail->IsHTML(true);

    $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';

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
?>
728x90
반응형