我知道如何在
PHPMailer中使用SMTP:
$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
它工作正常.但我的问题是:
创建一个函数,并包含/使用它.
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().
原文地址:https://www.jb51.cc/php/135303.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。