I've written a function within Controller to use PHPMailer and it works fine. After that I need this Function frequently and eventually I decide to write Library. But when do this and load Library within Controller, It has error like this :
Message: Call to undefined method PHPMailerOAuth::isSMTP()
After all I've figured out there is problem with path! I've tried what ever you're thinking but it doesn't work!
I've tried Controller as library
I've tried include()
,require_once()
,require
, with or without APPATH
.
I've search as much as I could. Even I've read about Third Party
but I don't understand.
Is there any idea to load PHPMailer file within Library?
Thank you in advance.
It's library called PHPMailer.php
class PHPMailer {
public function singleMail($setFromTitle,$setToMail,$setToName,$setSubject,$setMessage)
{
date_default_timezone_set('Etc/UTC');
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
require 'vendor/autoload.php';
$mail = new PHPMailerOAuth;
$mail->CharSet = 'UTF-8';
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->AuthType = 'XOAUTH2';
$mail->oauthUserEmail = "XXX@gmail.com";
$mail->oauthClientId = "XXX";
$mail->oauthClientSecret = "XXX";
$mail->oauthRefreshToken = "XXX";
$mail->setFrom('XXXy@zounkan.com', $setFromTitle);
$mail->addAddress($setToMail, $setToName);
$mail->Subject = $setSubject;
$mail->msgHTML($setMessage);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
And it's how I load this library within Controller's function :
$this->load->library('PHPMailer');
$this->phpmailer->singleMail($setFromTitle,$setToMail,$setToName,$setSubject,$setMessage);