Home › Forums › Back End › Optimising and consolidating multiple PHPMailer functions › Reply To: Optimising and consolidating multiple PHPMailer functions
April 6, 2014 at 4:40 pm
#167757
Participant
Would it be something likeā¦
Pretty much, yeah.
Question: where you have the variable $mail
, are you actually doing anything with it beforehand? or are you just doing something like
$mail = new PHPmailer;
sendEmail( $subject,$to,$message,$mail );
? if so, you could just make the new PHPmailer object inside the sendEmail
function.
public function sendEmail( $to, $subject, $message ){
try {
$mail = new PHPmailer;
$mail->IsSMTP();
$mail->Username = "[email protected]";
$mail->Password = "********";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->addAddress( $to );
$mail->From = '[email protected]';
$mail->FromName = 'Connectd.io';
$mail->AddReplyTo( '[email protected]', 'Contact Connectd.io' );
$mail->isHTML(true);
$mail->MsgHTML( $message );
$mail->Subject = $subject;
$mail->Send();
}catch(Exception $e) {
$general = new General($db);
$general->errorView($general, $e);
}
}
(also, there’s no reason to have two catch
blocks if they don’t do anything differently.)