Search the Community
Showing results for tags 'phpmailer'.
-
Hi, There is a new version of PHPMailer released (v. 5.2.2). It seems this new version is working well with MetYii's wrapper but I can't figure out how to use a great new PHPMailer 'callback' feature. PHPMailer documents it only by example: /* Callback (action) function * bool $result result of the send action * string $to email address of the recipient * string $cc cc email addresses * string $bcc bcc email addresses * string $subject the subject * string $body the email body * @return boolean */ require_once '../class.phpmailer.php'; $mail = new PHPMailer(); function callbackAction ($result, $to, $cc, $bcc, $subject, $body) { /* this callback example echos the results to the screen - implement to post to databases, build CSV log files, etc., with minor changes */ $to = cleanEmails($to,'to'); $cc = cleanEmails($cc[0],'cc'); $bcc = cleanEmails($bcc[0],'cc'); echo $result . "\tTo: " . $to['Name'] . "\tTo: " . $to['Email'] . "\tCc: " . $cc['Name'] . "\tCc: " . $cc['Email'] . "\tBcc: " . $bcc['Name'] . "\tBcc: " . $bcc['Email'] . "\t" . $subject . "<br />\n"; return true; } try { $mail->IsMail(); // telling the class to use SMTP $mail->SetFrom('you@yourdomain.com', 'Your Name'); $mail->AddAddress('another@yourdomain.com', 'John Doe'); $mail->Subject = 'PHPMailer Lite Test Subject via Mail()'; $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically $mail->MsgHTML(file_get_contents('contents.html')); $mail->AddAttachment('images/phpmailer.gif'); // attachment $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment $mail->action_function = 'callbackAction'; $mail->Send(); echo "Message Sent OK</p>\n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! } You can see a callback function and e-mail sending block. When using a wrapper, sending e-mail looks quite similar: Yii::app()->mailer->IsSMTP(); try{ Yii::app()->mailer->Host = Yii::app()->params['mail']['smtp_host']; Yii::app()->mailer->Encoding = Yii::app()->params['mail']['smtp_encoding']; Yii::app()->mailer->CharSet = Yii::app()->params['mail']['smtp_charset']; Yii::app()->mailer->WordWrap = Yii::app()->params['mail']['smtp_word_wrap']; Yii::app()->mailer->From = $model->email; Yii::app()->mailer->FromName = $name; Yii::app()->mailer->AddReplyTo($model->email); Yii::app()->mailer->AddAddress(Yii::app()->params['adminEmail']); Yii::app()->mailer->Subject = $subject; Yii::app()->mailer->getView('contact_form', array('name'=>$model->name, 'email'=>$model->email, 'subject'=>$model->subject, 'body'=>$body), 'main'); Yii::app()->mailer->action_function = 'mailerCallback'; Yii::app()->mailer->Send(); }catch(phpmailerException $e){ Yii::app()->user->setFlash('contact', $e->errorMessage()); }catch(Exception $e){ Yii::app()->user->setFlash('contact', $e->getMessage()); } $this->refresh(); } You may have notice I already added: Yii::app()->mailer->action_function = 'mailerCallback'; but... I have no idea where to put the 'mailerCallback' function within Yii application context. I tried to add it to controller class but it does not work this way. Can you help me please? Rgs, Ziggi