我正在尝试为PHPmailer创建不同设置的函数/开关。 (像这样:
function create_mailer($current_site,$from,$from_name){
require_once 'classes/PHPMailer/PHPMailerAutoload.php';
$mailer = new PHPMailer;
switch ($current_site){
case 'site1':
$mailer->isSMTP();
$mailer->Host = 'mail.site1.com';
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;
$mailer->Username = 'username1';
$mailer->Password = 'password1';
$mailer->From = $from;
$mailer->FromName = $from_name;
$mailer->isHTML(true);
return $mailer;
break;
case 'site2':
$mailer = new PHPMailer;
$mailer->isSMTP();
$mailer->Host = 'mail.site2.com';
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;
$mailer->Username = 'username2';
$mailer->Password = 'password2';
$mailer->From = $from;
$mailer->FromName = $from_name;
$mailer->isHTML(true);
return $mailer;
break;
}
}
在de index.php中,我做了类似的事情:
require 'functions/create_mailer.php';
$mailer = create_mailer('site1','mail1@sitename1.com','mailname');
$mail = new Mailer($mailer);
$mail->send('mailtemplate/new_bid.php',['something'=>'else'],function($m) {
$m->to('email@to.somebody');
$m->subject('mailsubject');
});
当我不使用开关时,邮件工作正常。 (Iff设置只是在index.php中我的意思) 我无法弄清楚为什么这不起作用,因为我总是认为这种必须有效:)
请告知。先谢谢。
答案 0 :(得分:0)
您正在呼叫create_mailer('sitename1','mail1@sitename1.com','mailname');
但正在使用'site1'
进行测试。
为您的开关添加默认设置,或致电create_mailer('site1','mail1@sitename1.com','mailname');