Hey guys, sorry if this has already been answered but I cannot seem to find it. I have a project going here and I am reusing the email call quite alot so I decided to try put it in the following function which is located in the
TestController class
public function email($message,$sendTo,$subject){
require Yii::getPathOfAlias('application.extensions') . '/PHPMailer_v5.1/class.phpmailer.php';
$mail = new PHPMailer(true);
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "test.net"; // SMTP server
$mail->Username = "test.com"; // SMTP server username
$mail->Password = "test"; // SMTP server password
$mail->Mailer = "smtp";
$mail->From = 'paul@test.com';
$mail->FromName = 'Paul';
$mail->AddAddress($sendTo);
$mail->Subject = $subject;
$body = $message;
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
}
Its called succellfully from a function in that controller like so
public function actionTest() {
$message = 'Test data';
$sendTo = 'whoever@hotmail.co.uk';
$subject = 'testing123';
$this->email($message, $sendTo, $subject);
}
However what im trying to do is call it from a different controller entirely, for example
TestController2 class
$message = 'More test dara';
$subject='Added As Participant in a contract';
$sendTo = $model->Email;
$email = new TestController();
$email->email($message, $sendTo, $subject);
//Ive also tried
//TestController::email($message, $sendTo, $subject);
However neither works, the erro i get is as follows
include(TestController.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory
and stack trace directs me to this part of the code
$email = new TestController();
Any help with this problem would be much appreciated, Thank you