我正在使用 PHPMailer,但我认为它占用了太多行并且觉得我可以使它更简洁。下面的一些参数是多余的,因为所有内容都将从同一个电子邮件地址发送。
我实际上是在问我是否可以将始终相同的参数放在其他地方(From、FromName、Username、Password、Host、Post、SMTPSecure、SMTPAuth)
我该怎么做?提前致谢。问候
我的代码是:
include("classes/phpmailer/class.phpmailer.php");
include("classes/phpmailer/class.smtp.php"); // note, this is optional
$mail = new PHPMailer();
$body = 'This is the body';
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "myemailaddress@gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
$mail->From = "myemailaddress@gmail.com";
$mail->FromName = "Admin";
$mail->Subject = "Welcome";
$mail->AltBody = 'This is the body'; //Text Body
$mail->WordWrap = 100; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("replyto@yourdomain.com","Admin");
$mail->SMTPDebug = 1;
$mail->AddAddress($email,$firstname." ".$surname);
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
// nothing is displayed
}