This is my shameless asking for help with something that should be simple. After a week of trying , I don’t know what else to do. I have an email function in my controller that errors out when Im using good credentials in email.php `
the controller code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
App::uses('CakeEmail', 'Network/Email');
class LeadsController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session', 'Flash', 'Email');
public function add() {
if ($this->request->is('post')) {
$Email = new CakeEmail();
$Email->config('smtp');
$Email->from('noreply@xxx.com');
$Email->sender('noreply@xxx.com');
$Email->to($this->request->data['Lead']['email']);
$Email->subject('Thanks for Contacting US at medpavilion');
$Email->emailFormat('html');
$emailContent = '<div style="background-color: #f2f2f2; padding: 20px;">
<h2 style="color: #333;">Thank you for your submission!</h2>
<p style="color: #333;">Please visit our website at <a href="https://www.example.com">www.example.com</a> for more information.</p>
<p style="color: #333;">Best regards,</p>
<p style="color: #333;">Your Company</p>
</div>';
$Email->send();
if ($this->Lead->save($this->request->data)) {
$this->Session->setFlash('Message Successfully Sent!.');
}
}
$this->render('/Pages/contact');
}
}
//. --------- end
So, if I’m getting this error:
2023-07-14 01:22:02 Error: [SocketException] SMTP server did not accept the password.
Request URL: /leads/add
Stack Trace:
#0 /srv/xxx.com/lib/Cake/Network/Email/SmtpTransport.php(96): SmtpTransport->_auth()
#1 /srv/xxx.com/lib/Cake/Network/Email/CakeEmail.php(1173): SmtpTransport->send(Object(CakeEmail))
#2 /srv/xxx.com/app/Controller/LeadsController.php(29): CakeEmail->send()
#3 [internal function]: LeadsController->add()
#4 /srv/xxx.com/lib/Cake/Controller/Controller.php(490): ReflectionMethod->invokeArgs(Object(LeadsController), Array)
#5 /srv/xxx.com/lib/Cake/Routing/Dispatcher.php(193): Controller->invokeAction(Object(CakeRequest))
#6 /srv/xxx.com/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(LeadsController), Object(CakeRequest))
#7 /srv/xxx.com/app/webroot/index.php(118): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#8 {main}---------------------------
Does that mean Absolutely it’s a password issue and nothing else?
I should add that when I do this in the email.php: and set $Email->config(‘default’); in the controller,
no error, but no email either.
public $default = array(
'transport' => 'Mail',
'from' => 'noreply@xxx.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
It runs with no error and no error message but the email never gets there.