Gauri deshmukh
Gauri deshmukh

Reputation: 89

PHP mailer in yii framework

I am using php mailer in yii frame work, can somebody pleas etell me how to include php mailer files in yii framework model to send mail?

following is my code but it is throwing error

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;
}

Upvotes: 1

Views: 2461

Answers (2)

Synchro
Synchro

Reputation: 37810

This line makes no sense at all:

return $sendmail = '[email protected]';

The code will never get beyond that point. Change it to:

$sendmail = '[email protected]';

You should also read the PHPMailer readme that tells you how to load the class files; Use one of: composer (preferred), the autoloader, or load the classes manually.

Upvotes: 0

Azraar Azward
Azraar Azward

Reputation: 1624

You can save the PHPMailer files inside vendor directory.

And you need to include it in the import array in main.php and console.php

'import'=>array(
    'application.vendor.PHPMailer.*',

Then you can call it as following in the Controller

$mail = new PHPMailer(true);

or there are extensions for Yii 1 and Yii 2, you can easily configure and start sending emails.

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

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

Upvotes: 2

Related Questions