Email configuration


#1

Please can anyone help me with configuration for email for my users to get the mail in their inbox after registering on my site. i am using cake 3.6


#2

Email configuration and usage are pretty well covered in the manual. What in particular are you having problems with?


#3

This is the error message i get after filling the registration form.

2019-01-15 00:51:24 Error: [Cake\Network\Exception\SocketException] php_network_getaddresses: getaddrinfo failed: Name or service not known
Request URL: /users/register
Referer URL: http://www.bleedingdevelopers.com/users/register
Stack Trace:
#0 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Mailer/Transport/SmtpTransport.php(207): Cake\Network\Socket->connect()
#1 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Mailer/Transport/SmtpTransport.php(162): Cake\Mailer\Transport\SmtpTransport->_connect()
#2 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Mailer/Email.php(2170): Cake\Mailer\Transport\SmtpTransport->send(Object(Cake\Mailer\Email))
#3 /home/u104044552/domains/bleedingdevelopers.com/public_html/src/Controller/UsersController.php(176): Cake\Mailer\Email->send(‘Hello info@rock…’)
#4 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Controller/Controller.php(596): App\Controller\UsersController->Register()
#5 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(120): Cake\Controller\Controller->invokeAction()
#6 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(94): Cake\Http\ActionDispatcher->_invoke(Object(App\Controller\UsersController))
#7 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/BaseApplication.php(235): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#8 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#9 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Middleware/CsrfProtectionMiddleware.php(107): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#10 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\Middleware\CsrfProtectionMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#11 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(156): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#12 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#13 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#14 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#15 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(98): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#16 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#17 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#18 /home/u104044552/domains/bleedingdevelopers.com/public_html/vendor/cakephp/cakephp/src/Http/Server.php(98): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#19 /home/u104044552/domains/bleedingdevelopers.com/public_html/webroot/index.php(40): Cake\Http\Server->run()
#20 {main}

my config/app.php

‘EmailTransport’ => [
‘webmail’ => [
‘className’ => ‘Smtp’,
/*
* The following keys are used in SMTP transports:
*/
‘host’ => ‘stmp.hosting24.com’,
‘port’ => 587,
‘timeout’ => 30,
‘username’ => ‘info@bleedingdevelopers.com’,
‘password’ => ‘xxxxxx’,
‘client’ => null,
‘tls’ => true,
‘url’ => env(‘EMAIL_TRANSPORT_DEFAULT_URL’, null),
],

],

/**
 * Email delivery profiles
 *
 * Delivery profiles allow you to predefine various properties about email
 * messages from your application and give the settings a name. This saves
 * duplication across your application and makes maintenance and development
 * easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
 * for more information.
 */
'Email' => [
    'default' => [
        'transport' => 'webmail',
        'from' => 'info@bleedingdevelopers.com',
       // 'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    ],
],

and my function to send mail in my controller is
public function Register(){
if($this->request->is(‘post’)){
$userTable = TableRegistry::get(‘Users’);
$user = $userTable->newEntity();
$hasher = new DefaultPasswordHasher();
$myname = $this->request->getData(‘username’);
$myemail = $this->request->getData(‘email’);
$mypass = $this->request->getData(‘password’);
//$this->request->data[‘role_id’] = 1;
$mytoken = Security::hash(Security::randomBytes(32));
$user->username = $myname;
$user->email = $myemail;
$user->password = $hasher->hash($mypass);
$user->token = $mytoken;

$user->created = date('Y-m-d H:i:s');
$user->modified = date('Y-m-d H:i:s');
if($userTable->save($user)){
    
            $email = new Email('default');
            $email->transport('webmail');
            $email->emailFormat('html');
            $email->from('info@bleedingdevelopers.com','George');
             $email->subject('Please your password have been sent to your email account');
            $email->to($myemail);
            
           $email ->send('Hello '.$myemail.'<br/>Please check your email link below to reset your password<br/><a href="http://bleedingdevelopers.com/users/verification/'.$mytoken.'">Reset Password</a><br/>Thank you for joining Us');
}else{
    $this->Flash->set('Register failed, Please Try Again',['element'=>'error']);
}

}

}
this is also my stmp setup from my service provider.

Webmail address https://webmail.hosting24.com
POP3 Host pop.hosting24.com
POP3 Port (secured) 995
IMAP Host imap.hosting24.com
IMAP Port (secured) 993
SMTP Host smtp.hosting24.com
SMTP Ports (secured) 587
MX Record mx1.hosting24.com

#4

getaddrinfo failed: Name or service not known means that it failed to look up the IP address associated with a host name. This points immediately at the server name you’ve used, which is stmp instead of smtp.