基本用法
$mail = new PHPMailer(true); try { $mail->SMTPDebug = SMTP::DEBUG_OFF; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->Host = 'smtp.163.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'xxx@163.com'; // SMTP username $mail->Password = 'xxx'; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted $mail->Port = 465; // TCP port to connect to //Recipients $mail->setFrom('xxx@163.com', '意见和反馈'); $mail->addAddress('xxx@qq.com'); // Add a recipient //$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 = 'xxx'; $mail->Body = $html; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); } catch (Exception $e) { Db::name('error_log')->insert([ 'type' => __CLASS__.'.'.__METHOD__, 'content' => $e->getMessage().';'.$mail->ErrorInfo, ]); throw new \Exception($mail->ErrorInfo); }