PHP yii 框架中的邮件程序

PHP mailer in yii framework

我在 yii 框架中使用 php 邮件程序, 有人可以告诉我如何在 yii 框架模型中包含 php 邮件程序文件来发送邮件吗?

以下是我的代码,但它抛出错误

Yii::$app->db->createCommand("update merchant_master set code='$code' where id='$mid'")->execute();

include(Url::base()."/PHPMailer/class.PHPMailer.php");
include(Url::base().'/PHPMailer/class.smtp.php');
include(Url::base().'/PHPMailer/PHPMailerAutoload.php');

$name= 'Test';
$mail_id ='dev3@mdcconcepts.in';
$idd = 'booking-ticket1475748775322';
$url='<a href="http://www.mdcfestival.com/book-now/uploads/'.$mid.'.pdf" target="_blank">here</a>'; 

return $sendmail = 'dev3@mdcconcepts.in';   
$message="Name:".$name."\r\n";
$message .=" ";
$message .= "EmailId:".$mail_id."\r\n";
$message .=" ";
$message .= "You can get your tickets by clicking this URL: ".$url."\r\n";
$email = new PHPMailer();
$email->From      = 'dev1@mdcconcepts.in';
$email->FromName  = 'MDCFestival';
$email->Subject   = 'MDCFestival Tickets';
$email->Body      = $message;
$email->AddAddress($sendmail);

//$email->AddAttachment($file_name);
if($email->Send()) {
    echo 11;
} else {
    echo 00;
}

您可以将 PHPMailer 文件保存在 vendor 目录中。

并且您需要将其包含在 main.php 和 console.php

的导入数组中
'import'=>array(
    'application.vendor.PHPMailer.*',

然后在Controller中可以这样调用

$mail = new PHPMailer(true);

或者有 Yii 1 和 Yii 2 的扩展,你可以轻松配置并开始发送电子邮件。

Yii 1 - http://www.yiiframework.com/extension/phpmailer/

Yii 2 - http://www.yiiframework.com/extension/zyx-phpmailer/

这一行完全没有意义:

return $sendmail = 'dev3@mdcconcepts.in';

代码永远不会超过那个点。将其更改为:

$sendmail = 'dev3@mdcconcepts.in';

您还应该阅读告诉您如何加载 class 文件的 PHPMailer 自述文件;使用 其中之一:composer(首选)、自动加载器,或手动加载 classes。