Error "Class 'Swift_EmbeddedFile' not found" when i try send email with yii2 advanced - yii2-advanced-app

I tried build application with auto send mail.
Before I build in yii2 advanced, I tried in yii2 basic and my code work.
But when i tried in yii2 advanced, I got error
Class 'Swift_EmbeddedFile' not found
Can somebody help me?
And this is my code :
code in /common/config/main-local.php
return [
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'mysmtp',
'username' => 'myusername',
'password' => 'mypassword',
'port' => 'myport',
],
],
],];
And my code in MyController :
Yii::$app->mailer->compose('layouts/index.php', [
'imageFileName' => Yii::getAlias('#app/mail/layouts/images/logo.png'),
'facebook' => Yii::getAlias('#app/mail/layouts/images/facebook.png'),
'twitter' => Yii::getAlias('#app/mail/layouts/images/twitter.png'),
'pinterest' => Yii::getAlias('#app/mail/layouts/images/pinterest.png')
]) // a view rendering result becomes the message body here
->setFrom('from#email.com')
->setTo($model->email)
->setSubject('Message Test 3')
->send();
Note : I have Swiftmailer extention.
Thanks in advance for your help guys.

Related

Cannot receive any mail using default mail of swift mailer in yii2

I tried to mail using default mail of swift mailer but didn't receive any mail.
here is my config
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail/views',
'useFileTransport' => true,
'enableSwiftMailerLogging' => true,
]
and here is code for send mail
\Yii::$app->mailer->compose('deleteMailTemplate',[
'name' => "Peter",
])
->setFrom("contact-atd#gmail.com")
->setTo("Peter.p#gmail.com")
->setSubject('Delete reminder mail')
->send();
I don't know what's the issue please help thanks in advance.
I think you have issue in email configuration. Please used following code and check i hope this will work.
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username',
'password' => 'password',
'port' => '465',
'encryption' => 'ssl',
],
],
$sendemail = Yii::$app->mailer->compose()
->attach(attachment path)
->setFrom(From Email)
->setTo($email)
->setSubject($subject)
->setHtmlBody($emailBody)
->send();

yii2 mailer smtp connection refused

When setting up my smtp mailer in the config file, it works fine. But if I manually create the SMPT mailer it fails (Connection refused). Can anybody assist?
Yii2 config file:
'components'=[
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
The following code in my controller does not work:
$mailer = new \yii\swiftmailer\Mailer();
$mailer->transport = new \Swift_SmtpTransport();
$mailer->transport
->setHost('smtp.gmail.com')
->setPort(587)
->setEncryption('tls');
$mailer->transport->setUsername('email#gmail.com');
$mailer->transport->setPassword('password');
and I receive an error message: Connection refused #111
I have tried port 465 on ssl and I receive the same message.
My main reason for doing this is that I have different client accounts, each of which has its own smtp. I therefore need one account per client and I cannot seem to do that via the config file.
Many thanks for your help.
I just tried it worked for me, I did as follow
'components'=[
'mailer' => [ //Your default mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
'mailer2' => [ //Your custom mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'new_email#gmail.com',
'password' => 'new_password',
'port' => 'new_port587',
'encryption' => 'new_tls',
],
]
following is for default config
Yii::$app->mailer->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
following with custom mailer config
Yii::$app->mailer2->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
create a component is the fastest solution, otherwise, you can use the parameter to store configuration, and call when needed.

Mail is not sending in cakephp 3.0

I Have faced lots of error and now soo close that hole send function is executing then then redirect to anather page but the problem is mail is not sending. Any Idea, Thank you in advance
<?php
namespace App\Controller;
use Cake\ORM\TableRegistry;
use App\Controller\AppController;
use Cake\Mailer\Email;
function send(){
$name=$this->request->data('name');
$receiver_email='adangwa111#gmail.com';
$Subject_Title=$this->request->data('sub');
$Sender_email=$this->request->data('yemail');
$email = new Email();
$email->template('invite', 'default')
->emailFormat('html')
->from('Amit#gmail.com')
->to('adangwa111#gmail.com')
->subject('About')
->send();
$this->redirect(['controller'=>'Recommand','action' => 'index']);
}
}
And this is my App configuration
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'transport' => 'Smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 35,
'username' => '*******#gmail.com',
'password' => '********',
'client' => null,
],
],
I had this configuration in my App file
'EmailTransport' => [
'Smtp' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 35,
'username' => '*******#gmail.com',
'password' => '********',
'from'=>'*******#gmail.com',
'client' => null,
'tls' => null,
],
],
'Email' => [
'default' => [
'transport' => 'Smtp',
'from'=>'*******#gmail.com'
],
],
Please check if this works fine on your server as well. I also tried many combinations before getting this work.
Its just front end problem. I have been trying action for long then atlast I connect it with front end. It work fine

Yii2 Signup Email option

How can I set up automatic email for signup activation link in yii 2.0.3 advanced application template and how link back to login page
in this new version?
Configure the Swiftmailer in common\config\main.php components array:
// for sending mail using swift mailer
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'your_host_name',
'username' => 'enter_your_username_here',
'password' => 'enter_your_password',
'port' => '25',
],
],
After this you can use the following code to send mails:
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
->setFrom('from#domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
contact/html is the template name which is there is common/mail folder and contactForm variable having value $form is passed to that template.
You can put the above code in your controller. But I will suggest make a commonfunction of it and use it from anywhere. Hope it helps.

cakephp : Define Datasource for email plugin

I have a problem with a datasoure configuration in cakephp email plugin , when I test my code in local server , it's fine , but in hosting server I have error message :
Datasource class Emails.ImapSource could not be found.
that's my code :
public $emailTicket = array(
'datasource' => 'Emails.ImapSource',
'server' => 'xxxxx.com',
'connect' => '{xxxxx.com:110/pop3/TLS/novalidate-cert}INBOX',
'username' => 'contact#xxxxx.com',
'password' => 'xxxxx',
'port' => '143',
'ssl' => true,
'encoding' => 'UTF-8',
'error_handler' => 'php',
'auto_mark_as' => array(
'Seen',
// 'Answered',
// 'Flagged',
// 'Deleted',
// 'Draft',
),
);
thank you for help !