I have tried this.
<?php
return array(
'driver' => 'smtp',
'host' => 'smtp.sendgrid.net',
'port' => 587,
'from' => array('address' => 'from#example.com', 'name' => 'John Smith'),
'encryption' => 'tls',
'username' => 'sendgrid_username',
'password' => 'sendgrid_password',
);
Mail::send('emails.demo', $data, function($message)
{
$message->to('jane#example.com', 'Jane Doe')->subject('This is a demo!');
});
But i am getting this error:
Failed to authenticate on SMTP server with username "sendgrid_username" using 2 possible authenticators
How to resolve this problem.
Please help me.
Make sure the settings are OK, username and password are correct, the function itself should work as you posted.
Related
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 trying to send mails through CakePHP, but I always got a 'Connection timed out' message. I've used two different configurations: gmail and 1and1, but result is the same.
This is my email.php file:
public $oneandone = array(
'host' => 'ssl://smtp.1and1.es',
'port' => 465,
'username' => 'my-address#my-domain.com',
'password' => '*****',
'transport' => 'Smtp',
'timeout' => 1);
public $gmail = array(
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my-address#gmail.com',
'password' => '****',
'timeout' => 1,
'tls' => true,
'transport' => 'Smtp');
And this is my remind function inside the UsersController.php file:
public function remind() {
App::uses('CakeEmail', 'Network/Email');
$this->set('url', $this->referer());
if ($this->request->is('post')) {
$Email = new CakeEmail('gmail');
$Email->from(array('my-address#my-domain.com' => 'Staff'));
$Email->to('destiny#hotmail.com');
$Email->subject('Password reminder');
$Email->send('Here is your current password: xxxxxx');
return $this->redirect(array('action' => 'login'));
}
}
The error I got is
if (!$this->_socket->connect()) {
throw new SocketException(__d('cake_dev', 'Unable to connect to SMTP server.'));
so I don't know why I'm not being able to connect. I've modified some params like tls, ssl but no results.
Within the same server (1and1) I can send emails with the standard mail() function, so I don't think it is a problem of PHP configuration. Correct me if I'm wrong.
Some ideas would be appreciated!
the following, worked me correctly. on Cakephp 2
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myEmail#gmail.com',
'password' => 'AwesomePass',
'transport' => 'Smtp'
);
Note that gmail uses port 465.
It is possible that gmail does not work if your site does not have ssl certification.
in this case you must use a smtp configuration
public $smtp = array(
'transport' => 'Smtp',
'from' => array('site#localhost' => 'My Site'),
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
with the following function
public function sendMail() {
App::uses('CakeEmail', 'Network/Email');
$templateVar = array(); //array variable to use in the template
$Email = new CakeEmail();
$Email->template('template_name', 'default') //View/Emails/html/template_name.ctp
->config('gmail')//gmail or smtp
->emailFormat('html')
->subject('Awesome subject')
->to('toUser#email.com')
->from(array('myEmail#gmail.com'=>'My name'))
->viewVars($templateVar)
->send();
}
Probably someone can see what I'm doing wrong here. When I use ->from('test#example.com') the mail sends just fine. But when i use >from('test#hotmail.com') the mail is not sent. Everything is done in mail configuration as well.
$data = array("content" => Input::get("content"));
Mail::send("emails.text", $data, function($message)
{
$message->to('toMe#myDomain.com')
->from('test#hotmail.com' , 'Contact form message!');
});
Config:
'driver' => 'smtp',
'host' => 'mail.cornex.se',
'port' => 587,
'from' => array('address' => "christopher#cornex.se", 'name' => "Kristoffer"),
'encryption' => 'tls',
Hotmail uses Outlook SMTP. Try this:You may need to make slight modifications, but make note of the host, specifically.
'driver' => 'smtp',
'host' => 'smtp-mail.outlook.com',
'from' => array('address' => "christopher#cornex.se", 'name' => "Kristoffer")
'port' => 587, // or 25
'encryption' => 'tls',
Start working with Laravel 4.2 I tried to send email using Gmail STMP server. Below is my app/config/mail.php.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'sample_address#gmail.com', 'name' => 'Sample'),
'encryption' => 'tls',
'username' => 'sample_address#gmail.com',
'password' => 'sample password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Below is my php code.
<!-- app/views/emails/welcome.php -->
Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
$msg->from('sample_address#gmail.com', 'Laravel Admin');
$msg->to('sample_receiver#gmail.com');
});
But it does not work. I have already configured my XAMPP php.ini on my MAC OSX. It only works when sending a normal PHP mail, not SMTP. The error message that I've got from Laravel on the view page is 'Error in exception handler'. I would like to see more error information but I don't know how to get more info. What is wrong with my code? What else do I need to do or configure? Thank you!
you can put your email and name in Input
Input::merge(array('email'=>'sample_receiver#gmail.com','name'=>'sample_name'));
Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
$msg->from('sample_address#gmail.com', 'Laravel Admin');
$msg->to(Input::get('email'), Input::get('name'))->subject('You have');
});
also change 'encryption'
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'sample_address#gmail.com', 'name' => 'Sample'),
'encryption' => 'ssl',
'username' => 'sample_address#gmail.com',
'password' => 'sample password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
You should change 'encryption' for ssl and in your gmail must be enabled IMAP access in config
When you are having problems with sending mails via gmail, try this. It worked for me.
Login with your gmail account and then go to:
https://accounts.google.com/b/0/DisplayUnlockCaptcha
and click continue. Then, you have few minutes to send your mail with your code.
After this, Google will allow sign in to that account from the new source.
Hi I just uploaded a site and am getting this error with the mail service.
Connection could not be established with host smtp.gmail.com [Connection refused #111]
This are my settings in my mail.php file.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'info#thesite.com', 'name' => 'Company Name'),
'encryption' => 'tls',
'username' => '*******',
'password' => '********',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
This works perfectly locally on my system but when i upload it live, it gives me errors, please help am at the verge of delivering a project, thanks!
I also faced same problem. As for me I had changed my SMPT configuring to port 25 (with SSL) and it's was fine.
I got my solution from google, you can see at here.
Try googlemail server with ssl encryption
return array(
'driver' => 'smtp',
'host' => 'smtp.googlemail.com',
'port' => 465,
'from' => array('address' => 'info#thesite.com', 'name' => 'Company Name'),
'encryption' => 'ssl',
'username' => '*******',
'password' => '********',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Found the answer to the problem, was from my web host service providers, i use shared host so i had to call them to configure my account with them to be able to send out email, hope this helps anyone who has such problems like me in the future and this is a proper smtp configuration for gmail.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'info#thesite.com', 'name' => 'Company Name'),
'encryption' => 'ssl',
'username' => '*******',
'password' => '********',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Try changing these.
'driver' => 'mail',
'port' => 587,
'encryption' => 'ssl',
This configuration works for me in GoDaddy server.
be sure you google authentication settings are enabled:
https://www.google.com/settings/security/lesssecureapps
change driver smtp to sendmail.it worked for me
MAIL_DRIVER=sendmail