CakePHP & AWS SES just stopped working - php

I've been using AWS SES with a CakePHP app for a few months, everything was working fine but we had a server problem meaning I had take the site off and get the server restored. Once I put the site back on I noticed emails wouldn't send and causing CakePHP to error.
The Error
2013-01-14 14:50:02 Error: [SocketException] SMTP Error: 535 Incorrect authentication data
#0 /public_html/lib/Cake/Network/Email/SmtpTransport.php(132): SmtpTransport->_smtpSend('QWhRZ2F0azQyTnh...', '235')
#1 /public_html/lib/Cake/Network/Email/SmtpTransport.php(61): SmtpTransport->_auth()
#2 /public_html/lib/Cake/Network/Email/CakeEmail.php(1059): SmtpTransport->send(Object(CakeEmail))
#3 /public_html/app/Controller/UsersController.php(1945): CakeEmail->send()
What I've done so far
I've checked both the domain and email are verified.
I regenerated new SMTP details just incase they where wrong.
Made sure my server time was correct using NTP
In the meantime I set up SMTP with a google business apps.
My Configuration (Some details altered for security)
public $smtp = array(
'transport' => 'Smtp',
'from' => array('no.reply#company.com' => 'Company'),
'host' => 'ssl://email-smtp.us-east-1.amazonaws.com',
'port' => 465,
'timeout' => 10,
'username' => 'AKIAICH5321NNDR2CMA',
'password' => 'AhQgat12Nx21c5e78S9Ufku0+4fw9LnRpuMTGZwjXT',
'client' => null,
'log' => false,
);
My Configuration for Google Business Apps (which works)
public $smtp = array(
'transport' => 'Smtp',
'from' => array('no.reply#company.com' => 'Company'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 10,
'username' => 'all#company.com',
'password' => 'b1t306b',
'client' => null,
'log' => false
);
Could I be missing some module of my server or has AWS changed something that happened round the same time as my server change? I'd really appreciate any help or advice. Thanks Jason

I've found the issue. Under WHM there is an option SMTP Restrictions, I disabled it.

Related

Configure CakePhp to send mail with SMTP

My web servers have disabled mail for security purposes I now need to reconfigure my cakephp code to send the emails via SMTP as recommended by the host.
My code runs fine on localhost with php mail enabled
use Cake\Mailer\Email;
class LoansController extends AppController
public function sendtestemail(){
$email = new Email();
$email->setViewVars(['name' => 'test test', 'subject'=>'subject test',
'message'=>'testit']);
$email
->template('bulkemail')
->emailFormat('html')
->to('info#test.co.ke')
->from('info#test.co.ke')
->subject($subject)
->send();
}
error:
Could not send email: mail() has been disabled for security reasons
Cake\Network\Exception\SocketException
My code runs fine on localhost with php mail enabled
It works fine in localhost but not in your remote hosting because your hosting company disabled it and you probably do not have much control over it.
To send an email in cakephp use Email class of Cakephp 3. In app.php under config folder, add a new entry in the table EmailTransport.
In your case ‘Smtp’. Specify host, port, username and password in it:
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
‘mail’=> [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' =>xxxxx', //gmail id
'password' =>xxxxx, //gmail password
'tls' => true,
'className' => 'Smtp'
]
],
Now in Controller, the function to send email uses above-written entry in transport() function as below.
Add path in controller- use Cake\Mailer\Email:
function sendEmail()
{
$message = "Hello User";
$email = new Email();
$email->transport('mail');
$email->from(['Sender_Email_id' => 'Sender Name'])
->to('Receiver_Email_id')
->subject(‘Test Subject’)
->attachments($path) //Path of attachment file
->send($message);
}
Also have in mind that many hosting companies also block default smtp ports. ( I'm aware that digital ocean does it, for example ). So, you might have to change that port or contact them to get it opened for you ( usually after some sort of verification ).
Some reference about what I just answered: https://www.digitalocean.com/community/questions/digital-ocean-firewall-blocking-sending-email
What worked for me is from https://book.cakephp.org/2/en/core-utility-libraries/email.html
Edit /app/Config/email.php
public $smtp = array(
'transport' => 'Smtp',
'from' => array('xxxxxxxxxx#gmail.com' => 'Betting site'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'xxxxxxxxxx#gmail.com',
'password' => 'xxxxxxxxxxpass',
'client' => null,
'log' => true
);

cakeEmail getaddrinfo failed: No such host is known

I'm trying to send an email in cakephp (no need to use ssl at the time), config seems fine but I keep getting the error above, below is my smtp config:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('test#mambihost.com' => 'Mambihost'),
'host' => 'mail.mambihost.com ',
'port' => 26,
'timeout' => 100,
'username' => 'test#mambihost.com',
'password' => 'secret',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
Why could this be happening? I'm running this in a wamp on my server which is inside a LAN. I can ping the host from the server with no problem but my app doesn't seem to reach it or something.
Could you help me please?

Extension YiiMaill (Swiftmailer) can't send SMTP from gmail

I've a PHP application that's running with Yii Framework and it's using the YiiMail extension that's is based in Swiftmailer.
My application was working perfectly yesterday, but today the follow error was launched:
fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
My Yii app config:
'mail' =>
array('class' => 'application.extensions.yii-mail.YiiMail',
'transportType' => 'smtp',
'transportOptions' => array(
'host' => 'smtp.gmail.com',
'username' => '**#gmail.com',
'password' => '***',
'port' => '465',
'encryption'=>'tls' ),
'viewPath' => 'application.views.mail',
'logging' =>false,
'dryRun' => false
)
ANSWER: A FAST SOLUTION
My app is running in Windows, so I did a fast configuration to solve this problem at moment.
I did a configuration with sendmail and it enable into my php.ini file.
Ps: The main problem is if you have many apps running in the same php. How don't this problem to me, it's is stand alone application, I just did.
Something like this:
sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port = 587
#default_domain = gmail.com it's is not necessary
auth_username= your gmail#gmail.com
auth_password=your password
php.ini
[mail function]
sendmail_path = "path to sendmail installation"
SMTP = smtp.gmail.com
smtp_port = 587
If your current config was previously working, then suddenly stopped. Consider looking into the following:
Generating an APP password for a gmail account
Enabling Less SecureApps settings for your gmail account
I have encountered a similar problem before, enabling Less Secure Apps, then when I set 2 Step Verification for my google account, it stopped working.
Then generating an APP password, did the trick!
This is my working smtp settings in my Yii2 project:
common/config/main-local.php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=bd-sys',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => '******#gmail.com',
'password' => '******',
'port' => 587,
'encryption' => 'tls',
],
],
],
];

Cakephp3 sending mails - no result

I'm trying to send email via cakephp3.
This is my app email config:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
],
],
And this is controller :
public function index() {
$this->autoRender = false;
$email = new Email('default');
if (
$email->from(['mymail#gmail.com' => 'My Site'])
->to('mymail#gmail.com')
->subject('About')
->send('My message')) {
print 'ok';
}
}
And now, if i run this function, result is printed 'ok' on monitor.
But no mail is on my testing email box, even span, nothing.
My question is, why cakephp tells me that sending was done, but no mail is present on my box ?
Thank You.
Your configuration is incorrect. cakePHP attempts to send the e-mail via smtp to your localhost.
Most likely you do not have an MTA (ie. exim, dovecot) installed locally and the request gets dropped. This should be visible as an error in you logs (if enabled).
An easy solution is to change the configuration to a working email service for testing, for example Gmail.
Example:
Email::configTransport('gmail', [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my#gmail.com',
'password' => 'secret',
'className' => 'Smtp',
'tls' => true
]);
Note that the host and port point to Gmail. This example is indicative and was taken from the official documentation.
More information on configuring email transports in cakePHP 3.0 here: http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports

Lravel Mail not sending -- Connection could not be established with host smtp.gmail.com [Connection timed out #110]

I just developed a laravel web application with mail system.
i got error like
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
controller
Mail::send('timesheet/emailtemplate',array('data'=>$query),function($message)
{
$message->to('example#gmail.com')->cc('expalecc#gmail.com')->subject('Work Report on - ');
});
email template file : emailtemplate.blade.php
<h2>hai</h2>
mail.php (config)
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => null, 'name' => null),
'encryption' => 'ssl',
'username' => 'myemail#example.com',
'password' => 'mypassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
instead of using smtp use Mandrill Driver it is simpler and quicker than use smtp server. by default laravel comes with Mandrill Driver. mandrill required Guzzle 4 HTTP library.. for geting that into your project add
"guzzlehttp/guzzle": "~4.0"
to your composer.json file (in your project root directory)
inside app/config/mail.php
change this line
'driver' => 'mandrill',
go to https://mandrillapp.com/settings
and sign up and generate api key
create an app/config/services.php configuration file if one does not already exist for your project and add below configurations and generated api key
return array(
'mailgun' => array(
'domain' => '',
'secret' => '',
),
'mandrill' => array(
'secret' => 'enter your mandrill api key here',
),
'stripe' => array(
'model' => 'User',
'secret' => '',
),
);
check this out this will be help full
Youtube video for setting up Mandrill for laravel

Categories