1 回答

TA贡献1785条经验 获得超4个赞
您可能会发现使用子类来配置它更容易,如下所示:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
class myMailer extends PHPMailer
{
public function __construct($exceptions = null)
{
$this->isSMTP();
$this->SMTPDebug = SMTP::DEBUG_OFF;
$this->Host = 'smtp.gmail.com';
$this->Port = 587;
$this->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$this->SMTPAuth = true;
$this->Username = 'example@gmail.com';
$this->Password = 'password';
parent::__construct($exceptions);
}
}
然后在脚本中,您可以执行以下操作:
$mail = new myMailer(true);
它将完成所有配置,随时可以使用。
也就是说,最好将“机密”(如密码)从代码中移出到外部环境变量或配置文件中,这样您就不会最终将密码推送到 git 存储库中。
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报