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 = '[email protected]';
$this->Password = 'password';
parent::__construct($exceptions);
}
}
然后在腳本中,您可以執行以下操作:
$mail = new myMailer(true);
它將完成所有配置,隨時可以使用。
也就是說,最好將“機密”(如密碼)從代碼中移出到外部環境變量或配置文件中,這樣您就不會最終將密碼推送到 git 存儲庫中。
- 1 回答
- 0 關注
- 113 瀏覽
添加回答
舉報