Yii2 Signup Email option - email

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.

Related

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

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.

Cakephp 3 email

I'm trying to use cakephp to send e-mail from my users, but I want each user uses they own e-mail for example
my app config
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'formulariosdsds#gmail.com',
'password' => '***',
'tls' => true,
],
it's used for App e-mais like, accont recovery and registration.
I want the users send with they own e-mail using the app like a transporter for each user. is there a way to do it?
Sure, you have to create a configuration transport each time a user send an email.
$transport = $user_data_email_config;
// first you drop to prevent to add a configuration pre existing and generate an error
Email::dropTransport($transport->name);
// now you create a custom configuration
Email::configTransport($transport->name, [
'className' => $transport->class_name,
'host' => $transport->host,
'port' => $transport->port,
'timeout' => 30,
'username' => $transport->username,
'password' => $transport->password,
'client' => $transport->client,
'tls' => $transport->tls
]);
$Email = new Email();
// for use the custom configuration, set the transport providing the transport name when you configure the email.
$Email->transport($transport->name);
// the rest of email configuration...

Yii2 send email with template problems

Hello I have problem with email creation.
the footer is duplicated:
<div class="footer">With kind regards, <?= Yii::$app->name ?> team</div>
Printing two times the same text
My settings in web.app:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#app/mail/',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'myemail#gmail.com',
'password' => 'mypassword',
'port' => '587',
'encryption' => 'tls',
],
],
And how I send email:
$content='test text';
\Yii::$app->mailer->compose('#app/mail/layouts/html', ['content'=>$content])
->setFrom('myemail#gmail.com')
->setTo('emailto#gmail.com')
->setSubject('test')
->send();

Yii2 REST ful Api how to send status code

Yii2 Restful API
In the above link they mention for GET Search method , Please anyone tell me for like POST create and PUT Update ...
In main.config under rules i created like,
['class' => 'yii\rest\UrlRule', 'controller' => 'v1/lkup-access-profile','extraPatterns' => ['POST create' => 'create']],
But its comes error as Method Not Allowed. This url can only handle the following request methods: POST.
yii\rest\UrlRule will create default REST URLs and actions. There's no need to add 'extraPatterns' => ['POST create' => 'create']. It's already built in. Check out the docs http://www.yiiframework.com/doc-2.0/yii-rest-urlrule.html
Use extraPatterns to extend default routes for controller. For example
['class' => 'yii\rest\UrlRule', 'controller' => 'v1/invite',
'extraPatterns' => [
'PUT {id}/accept' => 'accept',
'PUT {id}/reject' => 'reject',
],
],

Social Engine - Form Action is not calling method when submitted

I am developing a module for social engine 4. In a widget I have a simple form with a textfield and a button to submit the form.
I made a route in manifest.php file
'routes' => array(
'insert_link' => array(
'type' => 'Zend_Controller_Router_Route_Static',
'route' => 'profile/',
'defaults' => array(
'module' => 'hallive',
'controller' => 'videocover',
'action' => 'insertvideocoverlink'
)
),
)
I put this route inside the action of the form:
$this->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array(), 'insert_link'));
The method insertvideocoverlink is called when the button is pressed and everything works fine in localhost but when I use this code in a remote server (amazon web services) it does not work anymore. Why?