创建一个函数,并包含/使用它.
function create_phpmailer() {
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
return $mail;
}
并调用create_phpmailer()来创建一个新的PHPMailer对象.
或者您可以派生自己的子类,它设置参数:
class MyMailer extends PHPMailer {
public function __construct() {
parent::__construct();
$this->IsSMTP(); // telling the class to use SMTP
$this->SMTPAuth = true; // enable SMTP authentication
$this->Host = "mail.yourdomain.com"; // sets the SMTP server
$this->Username = "yourname@yourdomain"; // SMTP account username
$this->Password = "yourpassword"; // SMTP account password
}
}
并使用新的MyMailer().