Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Optimising and consolidating multiple PHPMailer functions Reply To: Optimising and consolidating multiple PHPMailer functions

#167754
Josh Johnson
Participant

Would it be something like:

$email->sendConfirmationEmail($arg1, $arg2, $arg3);

public function sendConfirmationEmail($arg1, $arg2, $arg3) {
   $message = file_get_contents('email_templates/register.html');
   $this->sendEmail($subject, $message);
}
    public function sendEmail($subject, $message, $mail) {

        $to = $email;

        try {
            $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(phpmailerException $e) {
            $general = new General($db);
            $general->errorView($general, $e);
        }catch(Exception $e) {
            $general = new General($db);
            $general->errorView($general, $e);
        }
    }