subject = $subject; return $this; } /** * 设置内容 * @param string $body */ public function setBody($body) { $this->body = $body; return $this; } /** * 设置不支持html时的内容 * @param string $string 内容 */ public function setAltBody($string) { $this->altBody = $string; return $this; } /** * 发送 */ public function send() { $success = false; $mail = new PHPMailer(true); try { $mail->CharSet = self::CHARTSET; //设定邮件编码 $mail->SMTPDebug = 0; // 调试模式输出 $mail->isSMTP(); // 使用SMTP $mail->Host = self::HOST; // SMTP服务器 $mail->SMTPAuth = true; // 允许 SMTP 认证 $mail->Username = $this->username; // SMTP 用户名 即邮箱的用户名 $mail->Password = $this->password; // SMTP 密码 部分邮箱是授权码(例如163邮箱) $mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议 $mail->Port = 465; // 服务器端口 25 或者 465 具体要看邮箱服务器支持 $mail->setFrom($this->fromAccount, $this->fromName); //发件人 $mail->addAddress($this->toAccount, $this->toName); // 收件人 $mail->isHTML(true); $mail->Subject = $this->subject; $mail->Body = $this->body; $mail->AltBody = $this->altBody; $success = $mail->send(); } catch (\Exception $error) { exit($mail->ErrorInfo); } return $success; } }