2017-01-16 69 views
1

我在yii框架中使用php邮件工作, 有人可以请教我如何在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 ='[email protected]'; 
$idd = 'booking-ticket1475748775322'; 
$url='<a href="http://www.mdcfestival.com/book-now/uploads/'.$mid.'.pdf" target="_blank">here</a>'; 

return $sendmail = '[email protected]'; 
$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  = '[email protected]'; 
$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; 
} 
+0

请将错误的详细信息添加到问题文章。 –

+0

@DmitryLozhkin它是抛出内部500错误 –

+0

@DmitryLozhkin我已经在模型中包含此代码。你能指导我如何将phpmailer库包括进去吗 –

回答

0

此行毫无意义可言:

return $sendmail = '[email protected]'; 

的代码将永远不会超越这一点。将其更改为:

$sendmail = '[email protected]'; 

您还应该阅读PHPMailer自述文件,该自述文件告诉您如何加载类文件;使用一个作者:首选,自动加载器,或手动加载类。