Hi guys,
I’m not too familiar with Yii yet, but trying to get there. I have a couple of questions, regarding importing extensions, and debugging of view rendering in failing cases. Here’s my problem and code:
I am trying to use PHPMailer code in my application. I’ve put it in the extension folder, and in the config:
'import'=>array(
'application.models.*',
'application.components.*',
'application.extensions.PHPMailer_v5.1.*',
),
Using this with a Yii::import statement in the model class I am working on gave me an “cannot open stream” error when instantiating a new PHPMailer object. So this is what i’ve got now:
public function sendRegistrationMail() {
try {
require Yii::app()->basePath. '/extensions/PHPMailer_v5.1/class.phpmailer.php';
require Yii::app()->basePath. '/extensions/PHPMailer_v5.1/class.smtp.php';
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = ""; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->From = "";
$mail->FromName = "Webmaster";
$mail->Subject = "This is the subject";
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("","Webmaster");
$mail->AddAddress("","");
$mail->IsHTML(true); // send as HTML
$mail->Send();
}
catch (Exception $e) {
Yii::trace(CVarDumper::dumpAsString($e->getTraceAsString()));
}
return true;
}
The code snippet above is called from my afterSave() method:
public function afterSave() {
$this->sendRegistrationMail();
return parent::afterSave();
}
What is happening after the save is the rendering of a view, however I do not get that far, I get a blank page. The model gets saved, so it is sendRegistrationMail that fails.
My questions are, how to import extensions in a cleaner way than in the method? because this is not very clean.
And if there are any good ways of debugging why the function fails. I get nothing in any logging. And I feel a bit helpless with no feedback as to why.
Hope someone can share some knowledge
Cheers!