Reputation: 9798
I'm using 1and1 server to host my CakePHP 3.2 application
This is how, I have configured email component on CakePHP
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'smtp.1and1.com',
'port' => 587,
'timeout' => 30,
'username' => '[email protected]',
'password' => 'password',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
But this is not working and no email is sent and gives Connection Time out
after 30 seconds.
From 1and1 email configuration page. It says
Outgoing port (TLS must be activated)
How to enable/configure TLS in CakePHP ?
Edit 2
the error stack shows SmtpTransport.php
protected function _connect()
{
$this->_generateSocket();
if (!$this->_socket->connect()) { // marked this line
throw new SocketException('Unable to connect to SMTP server.');
}
$this->_smtpSend(null, '220');
Action to send email
public function sendEmail($user_id = null, $email_id = null, $hash = null, $request = null)
{
switch($request) {
case 'register' : $subject = 'Account Confirmation';
$message = 'You have successfully registered. Click below link to verify it http://website.com/sellers/verify/'.$email_id.'/'.$hash;
break;
}
$email = new Email('default');
if ($email->from(['[email protected]' => 'Argo Systems'])
->to((string)$email_id)
->subject($subject)
->send($message)) {
return true;
} else {
return false;
}
}
and calling this function from same controller by
$this->sendEmail($user->id, $user->email, $hash, 'register');
Upvotes: 0
Views: 1262
Reputation: 505
I used below configuration in system for mail using gmail. it work fine. you just try with your server.
'EmailTransport' => [
'default' => [
'className' => 'SMTP',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 100,
'username' => '[email protected]',
'password' => 'exmple123',
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
Check with your port and host.Hope fully it will works
Try
Thanks
Upvotes: 0
Reputation: 9398
from the manual (bold is mine)
You can configure SSL SMTP servers, like Gmail. To do so, put the ssl:// prefix in the host and configure the port value accordingly. You can also enable TLS SMTP using the tls option:
so just set
'tls' => true
in your configuration array and try if it works
Edit
following this page I found that you don't even need to use the Smtp
transporter
just use a simple Mail
transporter this way
'default' => [
'className' => 'Mail'
]
There is no need to supply a username, password, or specify which mail server should be used to send the mail since this information is already contained in PHP variables.
try that!
Upvotes: 2