Skip to main content
edited tags; edited title
Link
200_success
  • 144.1k
  • 22
  • 188
  • 473

Using external php library in a project Wrapper class for PHPMailer

Source Link
Erdem Ece
  • 209
  • 2
  • 8

Using external php library in a project

Is this a right way to use/implement an external library into a project? If it's not how do you do it?

class Mail {
    protected $mail;

    public function __construct(PHPMailer $mail) {
        $this->mail = $mail;
        $this->mail->isHTML(Config::read('mail.isHtml'));
        $this->mail->setFrom(Config::read('mail.fromEmail'), Config::read('mail.fromName'));
    }

    public function sendMail ( $to, $subject, $body, $plainText ) {
        $this->mail->addAddress($to);
        $this->mail->Subject = $subject;
        $this->mail->Body = $body;
        $this->mail->AltBody = $plainText;

        $this->mail->send();
    }
}

and use it in anywhere in your app like this?

$test = new lib\Mail(new PHPMailer);

$test->sendMail('[email protected]', 'Subject', '<html>Hello username</html>', 'Hello username' );