把"phpmailer/phpmailer": "~5.2"放到conposer.json下面
命令行执行conposer update 在vendor下面会出现PHPMailer文件夹
进入vendor/composer/autoload_classmap.php
复制一行
写成最后一行,然后控制器use PHPMailer;
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ‘smtp.163.com‘; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘[email protected]‘; // SMTP username
$mail->Password = ‘gzp910728‘; // SMTP password
$mail->SMTPSecure = ‘tsl‘; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom(‘[email protected]‘, ‘鹏大哥‘);
// $mail->addAddress(‘[email protected]‘, ‘鹏哥哥‘); // Add a recipient
$mail->addAddress(‘[email protected]‘); // Name is optional
$mail->addReplyTo(‘[email protected]‘, ‘鹏哥哥‘);
// $mail->addCC(‘[email protected]‘);
// $mail->addBCC(‘[email protected]‘);
// $mail->addAttachment(‘/var/tmp/file.tar.gz‘); // Add attachments
// $mail->addAttachment(‘/tmp/image.jpg‘, ‘new.jpg‘); // Optional name
$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‘;
if(!$mail->send()) {
echo ‘Message could not be sent.‘;
echo ‘Mailer Error: ‘ . $mail->ErrorInfo;
} else {
echo ‘Message has been sent‘;
}