Can't send mail in cakePHP3 from Godaddy - php

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.

Related

CakePHP on AWS Bitnami LAMP server can't connect to database

I am just getting into PHP and I'm trying to get a server started and go through CakePHP's CMS tutorial. However I cannot get a database connection. I get the error: CakePHP is NOT able to connect to the database.
Connection to database could not be established: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
I have been trying to edit my app/config/app.php file. This is what I have:
'Datasources' => [
'default' => [
'className' => Connection::class,
'driver' => Mysql::class,
'persistent' => false,
'host' => 'localhost',
'port' => '3306',
'username' => 'root',
'password' => 'THE DEFAULT PASSWORD I USED TO GET INTO phpMyAdmin',
'database' => 'cake_cms',
'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',
//'encoding' => 'utf8mb4',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_URL', null),
],
'test' => [
'className' => Connection::class,
'driver' => Mysql::class,
'persistent' => false,
'host' => 'localhost',
'port' => '3306',
'username' => 'root',
'password' => 'THE DEFAULT PASSWORD I USED TO GET INTO phpMyAdmin',
'database' => 'cake_cms',
'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',
//'encoding' => 'utf8mb4',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
'log' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_TEST_URL', null),
],
],
Thanks in advance. I'm super new, so maybe I need to provide more information.

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.

Yii2 configure multiple mail components using swiftmailer

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.

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

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

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