Error: Transport config "Smtp" is missing in cakephp 3.x - php

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

Related

SMTP server did not accept the password. on upgrade to cakephp3.6

I upgraded my cakephp3.2 to cakephp3.6 . The emailing function doesnt work and i copied the same code in app file from the working emails in cakephp3.2 to the app file in cakephp3.6. The passwords exist and work fine. I edited them here for security. What has changed in 3.6?
It says the "SMTP server did not accept the password."
//in model
public function sendemail($to,$from,$subject,$message) {
$to='xxxx#gmail.com';
$Email = new Email('default');
// $Email->config('gmail3');
$Email->from(['xxx#gmail.com' => 'My Email'])
->to($to)
->subject($subject)
->send($message);
}//public
//in app file
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username'=>'xx#gmail.com',
'password'=>'xx',
'log' => true,
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'xx#gmail.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
'default' => [
'className' => 'Smtp',
'host' => 'smtp.gmail.com',
'port' => 587 //or 465,
'timeout' => 30,
'username' => 'email',
'password' => 'pass',
'client' => null,
'tls' => true,
],
This config works for me.

CakePHP: Transport config "gmail" is missing

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!!!

Can't send mail in cakePHP3 from Godaddy

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.

Email is not sending in cakephp 3.x in localhost

Here I am trying to send the email from localhost.I have configured the smtp server setting in php.ini and sendmail.ini file as well.And my code changes are
app.php
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => '******',
'password' => '********',
// 'client' => null,
// 'tls' => null,
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => '**********',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
Controller code.
$email = new Email('default');
try {
$res = $email->from('*****#**.**')
->to(['*****#**.**' => 'My Website'])
->subject('Tsting')
->send("hiii this is for testing ");
} catch (Exception $e) {
echo 'Exception : ', $e->getMessage(), "\n";
}

Send Email from SMTP remote server CakePHP 3

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.

Categories