【发布时间】:2016-12-13 06:23:41
【问题描述】:
我做了一个自定义类函数来设置PHPMailer所需的基本信息(所以我不需要每次都输入)。这是函数的确切代码。
<?php
class PHPMailer {
public static function send() {// I will just add here the addAddress
require_once 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "validusername";
$mail->Password = "validpassword";
$mail->setFrom('validusername', 'Valid Username');
$mail->addAddress('googol8080@gmail.com', 'Googol');
$mail->Subject = "Subject";
$mail->Body = "<a href=\"www.google.com\">www.google.com</a>";
$mail->IsHTML(true);
if (!$mail->send()) {
return "Error sending message" . $mail->ErrorInfo;
} else {
return "Message sent!";
}
}
}
到目前为止,它正在我的本地主机上运行,但我有问题:
- 这是一个好的做法吗?
- 代码正常吗?
- 这有什么缺点吗?
- 如果需要在此处优化性能,我需要做些什么来实现它?
我是 PHP 和 PHPMailer 的新手,任何小的答案都可能对我有帮助,谢谢。
【问题讨论】: