Yii2 send email with template problems - email

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();

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();

Can't send email with laravel 5.1 + gmail

I'm having troubles sending e-mails via a Laravel 5.1 application using gmail.
Here is my config file :
<?php
return [
'driver' => 'sendmail',
'host' => 'smtp.gmail.com',
'port' => 578,
'from' => array('address' => 'adresse#gmail.com', 'name' => 'Something'),
'encryption' => 'tls',
'username' => 'someaddress#gmail.com',
'password' => '****',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
Allowing less secure apps to access your account is turned on.
What config shall I use ?
You must to allow less secure apps here and Enable Unlock Captcha here
Also, Set .env as follows
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=something#gmail.com
MAIL_PASSWORD=*********
MAIL_ENCRYPTION=tls
And Set config/mail.php as follows
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => 'something#gmail.com',
'name' => env('MAIL_FROM_NAME', 'Admin'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME','something#gmail.com'),
'password' => env('MAIL_PASSWORD','*********'),
'sendmail' => '/usr/sbin/sendmail -bs',
Hope it's Help!

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

Do you have any idea on how to implement efax using SMTP Mail Driver (MAILGUN)

This is the sample email I received
This is my code:
Laravel 4.2
Controller:
Mail::send('emails.patient.fax-note'){
$message->to('61756041159#efaxsend.com');
$message->to('sunnycris1229#gmail.com', "Sunny");
$message->subject('Test Fax Notes Using smtp.mailgun.org');
$message->from('support#lktconsult.com');
} , "-f support#lktconsult.com");
mail.php setting
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => array('address' => "support#lktconsult.com", 'name' => "Hippocamp"),
'encryption' => 'tls',
'username' => "support#lktconsult.com",
'password' => "mypassword",
services.php
'mailgun' => array(
'domain' => 'sandbox9a694deec43645249032794f0b054c82.mailgun.org',
'secret' => 'my key here',
),
My Code works perfectly in the email, but not in efax, because efax only accept the mail if you send it to :61756041159#efaxsend.com and most importantly from: support#lktconsult.com , My problem is, the image I attached is the original email I received in my gmail.. stating that it came from : Received: from mail1.static.mgsend.net (mail1.static.mgsend.net. [104.130.122.1]) thats why efax does not accept the email.