郵件email

參考地址:https://blog.csdn.net/baidu_30000217/article/details/52942258php

郵箱配置地址:http://service.exmail.qq.com/cgi-bin/help?id=28&no=1000585&subtype=1 ide

 切記郵箱密碼不是平時登陸的密碼 而是第三方登陸受權碼ui

  操做步驟 設置-》用戶-》POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務spa

    開啓POP3/SMTP服務  IMAP/SMTP服務.net

  點擊【 生成受權碼debug

代碼:code

 
 
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
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 = 1; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.qq.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '978144***@qq.com'; // SMTP username
$mail->Password = '********'; // 是受權碼 不是密碼SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to

//Recipients
$mail->setFrom('978144***@qq.com', 'Mailer');
$mail->addAddress('1562096****@163.com', 'Joe User'); // Add a recipient
// $mail->addAddress('ellen@example.com'); // Name is optional
// $mail->addReplyTo('info@example.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');

//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;
}
相關文章
相關標籤/搜索