我制作了一个自定义类函数来设置 PHPMailer 所需的基本信息(因此我不需要每次都输入它)。这是该函数的确切代码。
<?php
class PHPMailer {
public static function send() {// I will just add here the addAddress
require_once 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "validusername";
$mail->Password = "validpassword";
$mail->setFrom('validusername', 'Valid Username');
$mail->addAddress('googol8080@gmail.com', 'Googol');
$mail->Subject = "Subject";
$mail->Body = "<a href=\"www.google.com\">www.google.com</a>";
$mail->IsHTML(true);
if (!$mail->send()) {
return "Error sending message" . $mail->ErrorInfo;
} else {
return "Message sent!";
}
} …Run Code Online (Sandbox Code Playgroud)