i get "Unknown email configuration 'gmail' " error , while trying to send an email using Cakephp ,is that because i'm sending it from localhost (xampp) ?
if($this->User->save($this->request->data)){
$message='Click on the link below to complete registration ';
$confirmation_link='www.sitename.com/users/verify/t:'.$hash.'/n:'.$this->data['User']['username'].'';
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');
$email->Email->from = 'myemail#gmail.com';
$email->Email->to=$this->data['User']['email'];
$email->Email->subject = 'Confirm Registration';
$email->Email->smtpOptions = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myemail#gmail.com',
'password' => 'mypassword',
'transport' => 'Smtp'
);
$email->send($message . " " . $confirmation_link);
$this->Session->setFlash(__('you should activate your account'));
}
}
In order to use new CakeEmail('gmail') you have to config gmail in your configure file (/Config/email.php) such as:
public $gmail = [
'transport' => 'Mail',
'from' => 'you#localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
];
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html
new CakeEmail('gmail') will read your gmail config and you will not have to configure it in your application.
If you do all your configuration in your application, perhaps you would like to use new CakeEmail();
Related
I do not have any knowledge about cakephp mail so explain the solution briefly I mean what to do and how to do from the beginning.
From the cakephp official side I just used this "use Cake\Mailer\Email;" and then the mail function but a error message shows like as shown below
Could not send email: mail(): Failed to connect to mailserver at
quot;server.com" port 25, verify your "SMTP" and
quot;smtp_port" setting in php.ini or use ini_set()
MY users controller login function
public function login() {
$this->viewBuilder()->setLayout('');
if ($this->request->is('post')) {
$data = $this->request->getData();
$query = $this->Users->find()->where(['email' => $data['email'], 'password' => md5($data['password'])]);
if ($query->count()) {
$user = $query->first()->toArray();
$this->Auth->setUser($user);
//FOR MAIL START
ini_set('SMTP', "server.com");
ini_set('smtp_port', "25");
ini_set('sendmail_from', "restrange5#gmail.com");
$email = new Email('default');
$email->setFrom(['restrange5#gmail.com' => 'My Site'])
->setTo('ramakantasahoo835#gmail.com')
->setSubject('About')
->send('My message');
//FOR MAIL END
$this->Flash->success(_('Login Successfull'));
$this->redirect(['action' => 'dashboard']);
} else {
$this->Flash->error(__('Username/Password not found!!'));
return $this->redirect($this->referer());
}
}
}
How much I know as I have just changed in users controller only. What else I have do please suggest.
**Your cofiguration in app.php file is something like this **'
EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'email here',
'password' => 'password here',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
]
I am sending email with CakePHP framework.
Following is the code I have added in function :
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('gmail');
$Email->from(array(
ADMIN_EMAIL => 'kioui'
));
$Email->to('pankhiwalia#gmail.com');
$Email->subject('test');
$Email->emailFormat('text');
$p = $Email->send();
and under Config/email.php file I have added following smtp settings:
public $smtp = array(
'transport' => 'Smtp',
'from' => array(ADMIN_EMAIL => ADMIN_NAME),
'host' => 'ssl://localhost',
'username' => 'kiouiapp#kioui-apps.com',
'password' => 'Fr00Fr00',
'client' => null,
'log' => true,
'timeout' => '30',
'tls' => false,
'port' => 465,
);
Please tell me did I miss any line?
So I am debugging some code that someone else wrote and it utilises the cakephp cake email thing. I have never used it before and have never written an email function before either.
When the function executes it outputs cakes standard: "Error: An Internal Error Has Occurred"
as well as this line:
SMTP Error: 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 h66sm5396348yhb.7 - gsmtp
The code is here:
public function newAppEmail($email_addr, $password) {
$Email = new CakeEmail();
$Email->config('default');
$Email->sender(array('polarontest#gmail.com' => 'Polaron'));
$Email->from(array('polarontest#gmail.com' => 'Polaron'));
$Email->to($email_addr);
$Email->subject('Eligibility Check');
$Email->template('newapp');
$Email->emailFormat('text');
$Email->viewVars(array('name' => $this->request->data['Applicant']['first_name'], 'email' => $this->request->data['Applicant']['email'], 'password' => $password));
$Email->attachments(array(
'Polaron - PL Passport - Info Pack - 2013.pdf' => array(
'file' => APP . 'documents/Email_attachments/Polaron - PL Passport - Info Pack - 2013.pdf',
'mimetype' => 'pdf'),
));
$Email->send();
}
and this is the config file:
<?php
class EmailConfig {
public $default = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'company name'),
'sender' => array('email#email.com' => 'company name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
public $fast = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'Test Mail name sender'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
}
Can anyone shed some light on what might be wrong and where I should look to fix it?
Well, SMTP Error 535 means that authentication fails, which is easy to find out.
The exception is thrown because of that. So get the right credentials and try again, this is not an issue of the php code but your credentials.
If your login / password is correct, test the configuration:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('email#gmail.com' => 'Name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'email#gmail.com',
'password' => '**********',
'client' => null,
'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
What I did
public $smtp = array(
'transport' => 'Smtp',
'from' => array('me#mydomain.com' => 'test'),
'host' => 'mail.mydomain.com',
'port' => 80,
'timeout' => 60,
'username' => 'me#mydomain.com',
'password' => 'me123',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
$email = new CakeEmail('Smtp');
$result = $email->template('welcome_mail','default')
->emailFormat('html')
->to($to_email)
->from('me#mydomain.com')
->subject('Welcome')
->viewVars($contents);
if($email ->send('Smtp'))
{
echo ('success');
}
what I am doing wrong here?
Please can anyonce explain smtp settings here?
what is host,username,password,client?
Please guide me what is host
which username and password I have to set here
I would add the Email Config to your email.php file located in /app/Config/email.php , if it doesn't exist copy email.php.default to email.php, Change the smtp settings there
public $smtp = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'my#gmail.com',
'password' => 'secret'
);
At the top of your Controller above class Controller extends AppController add,
App::uses('CakeEmail', 'Network/Email');
Then to send an email, try
$Email = new CakeEmail();
$Email->from(array('me#example.com' => 'My Site'))
->to('you#example.com')
->subject('About')
->send('My message');
To test emails what I usually do is send them to the Cake Logs,
**In /app/Config/email.php, include: ( The log output should be /app/tmp/logs/debug.log )
public $test = array(
'log' => true
);
Also doing this add 'test' to your $Email variable like,**
$Email = new CakeEmail('test');
I need help guys. I can't get this working. Could you help me?
Thanks in advance!
config/email.php
public $default = array(
'transport' => 'Mail',
'from' => 'sender#yahoo.com',
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
FeedbacksController.php
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
*
*
*
public function send() {
$email = new CakeEmail('default');
$email->emailFormat('text')
->to('recipient#yahoo.com')
->from('sender#yahoo.com')
->send('Message Body');
}
The above code gives me an error:
Could not send email.
Error: An Internal Error Has Occurred.
You can use this :
In the app/config/email.php add this new config
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'adresse#gmail.com',
'password' => 'secret',
'transport' => 'Smtp',
'timeout' => 1
);
After that and in your controller you have to call :
$email = new CakeEmail('gmail');
That is it.
In my experience ive had issues setting the ->from to a single string, and have found that doing ->from(array('emailaddress' => 'name')) has been more successful.
Also im not sure if setting a subject value is required to work sucessfully?