なんとなくやる機会があったので
いちおう忘れないようにメモメモ
まずは composer で phpmailer をインストール
1 |
composer require phpmailer/phpmailer |
https://github.com/PHPMailer/PHPMailer
あとはこんな感じ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
use PHPMailer\PHPMailer\PHPMailer; $mail = new PHPMailer(true); $host = 'smtp.gmail.com'; $userName = 'xxx@gmail.com'; $password = 'xxxxx'; $from = 'xxxxxx'; $fromname = 'xxxxx'; $to = 'xxxxxxxxx'; $subject = '件名'; $body = '本文'; $mail->SMTPDebug = 2; $mail->isSMTP(); $mail->SMTPAuth = true; $mail->Host = $host; $mail->Username = $userName; $mail->Password = $password; $mail->SMTPSecure = 'tls'; $mail->Port = 587; $mail->CharSet = "utf-8"; $mail->Encoding = "base64"; $mail->setFrom($from, $fromname); $mail->addAddress($to); $mail->Subject = $subject; $mail->Body = $body; $mail->send(); |