I'm trying to make a function/switch for diffrent settings for the PHPmailer. (something like this:
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;
}
}
In de index.php I've made something like :
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');
});
When i don't use the switch the mailer is working. (Iff the settings are just in the index.php i mean) I cant figure out why this isn't working beacause i alway thought that this kind must work:)
please advice.
thanks in advanced.