I'm using CakePHP 3.0.15 so I had to use Cake\Network\Email\Email; instead of use Cake\Mailer\Email;. Anyways, I have my EmailTransport in app.php configured like this:
'EmailTransport' => [
'gmail' => [
'className' => 'Smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'examplesender#gmail.com',
'password' => 's2d5f8t9',
'client' => null,
'tls' => null,
]
],
And have this in my controller:
$email = new Email();
$email->transport('gmail')
->to('examplereveiver#gmail.com', 'Example Receiver')
->from('examplesender#gmail.com', 'Example Sender')
->subject('Test Subject')
->send('Message!!!!!');
Then it gives me the error:
Transport config "gmail" is missing.
However, when I configure the transport in my controller, just before using it, like this:
Email::configTransport('gmail', [
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'examplesender#gmail.com',
'password' => 's2d5f8t9',
'className' => 'Smtp'
]);
It works and sends the email. Still, I'd like to configure the transport in app.php so I would be able to use the same transport config multiple times.
Thanks!!!
Related
I'm using Gourmet/Email and unable to send mail on Gadaddy from zoho.com hosted account, although everything was working well locally. My transport config is as follow :
'default' => [
'transport' => 'default',
'host' => 'ssl://smtp.zoho.com',
'port' => 465,
'username' => 'address',
'password' => 'pass',
'emailFormat' => 'both',
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
'className' => 'Smtp'
],
I'm getting such a response :
Connection refused
Cake\Network\Exception\SocketException
Can somebody help me fix this ?
I've changed Smtp into Mail for className as found here :
'default' => [
'transport' => 'default',
'host' => 'ssl://smtp.zoho.com',
'port' => 465,
'username' => 'address',
'password' => 'pass',
'emailFormat' => 'both',
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
'className' => 'Mail'
],
And it's fixed.
I want to send the email from different email accounts to users.
How I can configure multiple $mailer components?
Here is what I have implemented currently in main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'xxxxxxxxx',
'password' => 'yyyyyyyyyy',
'port' => '465',
'encryption' => 'ssl',
]
],
Have you tried this?
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'xxxxxxxxx',
'password' => 'yyyyyyyyyy',
'port' => '465',
'encryption' => 'ssl',
]
],
'mailerb' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'xxxxxxxxx',
'password' => 'yyyyyyyyyy',
'port' => '465',
'encryption' => 'ssl',
]
],
Access:
Yii::$app->mailer->compose()
Yii::$app->mailerb->compose()
To use Mailer, you should configure it in the application configuration like you just did in main-local.php
To send an email, you may use the following code:
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
->setFrom('from#domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
Where in:
->setFrom(array('mail1#gmail.com' => 'NAME','mail2#gmail.com' => 'NAME2'))
You may pass an array of addresses if this message is from multiple people. You may also specify sender name in addition to email address using format: [email => name].
Gmail disallows overriding the FROM name except from verfied email addresses that you prove to gmail you own. Either choose a different email server or go to your gmail settings and change it to another valid email address that you can receive email from.
Transport config "Smtp" is missing in cakephp 3.x
I have tried some of the configuration which are as follows:
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'xxxxxxxxx#gmail.com',
'password' => 'xxxxx',
],
],
'Email' => [
'default' => [
'from' => array('site#localhost' => 'Data Mining'),
'transport' => 'Smtp',
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
],
],
And i have used below code to send email.
$mail = new Email('default');
$mail->emailFormat('html');
$mail->template($template, null)->viewVars(array('body' => $mailBody));
$mail->to($email_to);
$mail->subject($subject);
$mail->replyTo(Configure::read('config.NOREPLY_EMAIL'));
$headers = array(
'X-MC-MergeVars' => '{"NAME": "Khushang", "REGARDS":"Khushang"}',
'X-MC-Template' => 'test-by-Khushang'
);
$mail->setHeaders($headers);
$mail->send();
Thank you so much...
You are giving transport config as Smtp in Email but you have not defined it in EmailTransport config.
Either set 'transport' => 'Smtp', to 'transport' => 'default',
OR
Set 'default' under 'EmailTransport' to 'Smtp'
Cakephp 3x set to app.php in config folder
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 600,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
'mailjet' => [
'host' => 'smtp.xxxxxxx.com',
'port' => 465,//your ssl or none ssl port no
'username' => 'xxxxxxxxxx', //your smtp mail id
'password' => '***************', //your email password
'timeout' => 60,
'secure' => 'ssl',
'tls' => false,
'className' => 'Smtp'
]
],
Your Controller page
$email = new Email();
$email->transport('mailjet');
$email->from($from)
//->attachments(TICKET_PDF . $file)
->to($to)
->emailFormat('html')
->subject($subject)
->viewVars(array('msg' => $message))
->send($message);
I wanted to ask about sending emails in cakephp3.
I am using cakephp3 docs, and configured everything as example shows.
But, when I try to send mail, this error appears:
Could not send email: unknown
//app.php
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.gmail.om',
'port' => 465,
'timeout' => 30,
'username' => 'mymail#gmail.com',
'password' => 'password',
'client' => null,
'tls' => null,
],
],
ContactController:
public function contact() {
if (isset($this->request->data) AND ($this->request->is('post'))) {
$email = new Email('default');
if ($email->from(['mymail#gmail.com' => 'My Site'])->to('othermail#gmail.com')->subject('Hello')->send('Message')) {
//pr( 'ok');
}
}
}
Is this a generic error message (, which may have many reasons, in my opinion)? it has no value in context of debug.
You want to use an SMTP server, but you've configured to use the Mail transport!
The className option should be set to Smtp. The host should probably also be different (ssl:// prefixed), or you should enable TLS, please be sure that you read through the questions/answers found with the search linked below.
See also
Cookbook > Email > Configuring Transports
https://stackoverflow.com/search?q=[cakephp]+gmail
The host name in default configuration is incorrect.
it should be
'host' => 'smtp.gmail.com',
instead of
'host' => 'smtp.gmail.om',
One thing that's always forgotten is the Email profiles
`'Email' => [
'default' => [
'transport' => 'gmail', //this allows the email class to use the gmail settings
'from' => 'youremail#gmail.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],`
And by the way you can set up multiple profiles for the like testing, development etc
use Cake\Mailer\Email;
Email::configTransport('gmail', [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my#gmail.com',
'password' => 'secret',
'className' => 'Smtp',
'tls' => true
]);
Yous this code : Replace My#gmail.com and Secret with you credentials offcourse and after that use you code it will work.
I'm facing some problems configuring my app to send Mails from my smtp server, which is located in one remote hosting with 1and1.
I don't know if I'm missing something:
I've changed my app.php to the values given by my hosting provider:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
'host' => 'smtp.1and1.com',
'port' =>'587' ,
'timeout' => 30,
'username' => 'me#dns.com',
'password' => '******',
'client' => null,
'tls' => null,
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => '#localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
Here you can see the instructions given by my hosting provider to connect to their smtp server.
I don't get any result.
Does anybody have an Idea what may I be missing?
I got it working setting classname as 'Mail' and the rest of the parameters as default. Please, do as follows:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
],
],
In my case only was problem in className.
For using gmail or office365 server it should be so:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.office365.com',
'port' => 587,
'timeout' => 30,
'username' => 'my#email.com',
'password' => 'myPassword',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
Please do as following:
//Adding Smtp information for sending mail through smtp instead of php mail function on local server / live server
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.1and1.com',
'port' =>'587' ,
'timeout' => 30,
'username' => 'me#dns.com',
'password' => '******',
'client' => null,
'tls' => null,
],
],
You can also enable tls to 'tls' => true if required.