CakePHP Cake Email SMTP Gmail - php

I have a problem with getting Cake Email to work properly.
I set everything up exacly as specified in cookbook (http://book.cakephp.org/2.0/en/core-utility-libraries/email.html section 'Configuration'). When I test it on localhost (xampp) everything works like a charm, the problem is, when I upload files on my web server, and try to execute it (send email) I get "Network is unreachable".
It seems to me, that there is probably some issue on server-side, but what could that be, and how to fix that?
Thanks in advance.
EDIT:
My code, as requested.
/app/Config/email.php
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'wykresl***14#gmail.com',
'password' => '***********',
'transport' => 'Smtp',
'timeout' => '30'
);
in Controller
public function test()
{
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('gmail');
$Email->from(array('wykreslanka.2014#gmail.com' => 'Wykreślanka 2014'));
$Email->to('si***1#gmail.com');
$Email->subject('test');
$Email->template('newsletter');
$Email->emailFormat('html');
$Email->viewVars(array('post_id'=>0,'post_title'=>'Tytuł','post_body'=>'Body','quote_is'=>false));
$Email->send();
$this->Session->setFlash('Poszło','success');
return $this->redirect(array('action' => 'all'));
}

Typically, most web hosting services block external SMTP connections for some reason I'm still trying to understand. One such webhost I know is JustHost.
They want you to use their local smtp server... I would suggest you get in contact with your webhosting service a I'm 100% sure its something on their part and not with your code.
My webhost refused to listen so the best alternative I used was MailGun http://www.mailgun.com/
This allows you to send an email using an php-api that they provide. However you wont be able to use your gmail address.

Related

Laravel mail sending is not working in the cloud instance [duplicate]

When I try to send an e-mail through my website running Laravel 4, I get this exception:
{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}
Here is my mail config:
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'mymail#gmail.com', 'name' => 'myname'),
'encryption' => 'ssl',
'username' => 'mymail#gmail.com',
'password' => 'lol',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I've tried the disable link i've found by googling this issue except it didn't make a difference.
Is there a way to tell Google "stop blocking this IP, it's me" ?
I tried the same thing and got the same error. So i personally checked my gmail account and i had a message from Gmail itself letting me know that they'd blocked an access attempt to my email account.
They showed an option to disable this security setting by visiting https://www.google.com/settings/security/lesssecureapps.
Things will actually be more straight forward if you visit that link already logged in into your Gmail account.
Warning
As #kodfire stated:
On May 30, 2022, this setting will no longer be available.
support.google.com/accounts?p=less-secure-apps&hl=en
Go to this link and disable unlock Captcha
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Try this:
Change port to 587
Goto gmail setting https://www.google.com/settings/security/lesssecureapps
and active it.
https://www.google.com/settings/security/lesssecureapps and active it.
https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.
'port' => env('MAIL_PORT', 587), <br>
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
I had lot of issues finding answer for this. Then after doing lot of trial and error i have found an solution to this. Most of the solution above worked for other but it help me upto 50%.
So, This is how it worked for me (100%):
Activate 2 step Verification in google
Now you will be able to create app. Open it.
Create new app (other app) and give your app name.
Now generate password.
Next in laravel, Goto .env file and change
MAIL_USERNAME= 'App Name you created'
MAIL_PASSWORD= 'Generated Password for that app'
This should be able to send emails from your gmail account.
Please leave a comment if it doesn't works for you.
Did you activate 2-step google authentification? If so, you need to define a new "application-specific password" password: http://www.google.com/landing/2step/.
Remove the #gmail.com from username, already you mentioned smtp. So no need #gmail.com on your username. I'm 100% sure it is your problem, because I had that problem.

CakePHP 2.x SparkPost Plugin

I was developing one web application in cakephp 2.2.3. that application I was using CakeEmail. But Now I want to implement SparkPost plugin for email deliver.
I spend lots of time in google but not getting any satisfied result. All are code I found cakephp 3.0 or higher.
Below I have posted some links for cakephp 3.x -
https://github.com/syntaxera/cakephp-sparkpost-plugin
https://github.com/narendravaghela/cakephp-sparkpost
Please help me and give me any idea about to implement sparkpost in cakephp 2.x.
SparkPost supports SMTP so you could configure CakePHP for that. Here's a (guessed-at) configuration stanza:
class EmailConfig {
public $sparkpost = array(
'host' => 'smtp.sparkpostmail.com',
'port' => 587,
'username' => 'SMTP_Injection',
'password' => 'YOUR_API_KEY_WITH_SMTP_PRIVILEGES',
'transport' => 'Smtp',
'tls' => true
);
}
Then in your controller code, you would instantiate a CakeEmail instance using the config stanza named above:
$email = new CakeEmail();
$email->config('sparkpost');
$email->from(...)->to(...)->subject(...)->send();

Send unauthenticated Google SMTP message using Zend_Mail

I am trying to write a PHP script for a live production server to check if the IP whitelisting for the open SMTP relay settings on a Google account works properly.
Since the server is currently live I don't want to change any of the /etc/postfix/main.cf settings for the existing email solution, and thought I would try to write an isolated Zend_Mail script that could test it independently, but I'm having difficulties getting Zend_Mail to acknowledge an SMTP connection without login credentials.
I've tried different variations on
$domain = 'foo.bar.com';
$config = array('ssl' => 'tls', 'username' => 'noreply#bar.com');
$transport = new Zend_Mail_Transport_Smtp($domain, $config);
Zend_Mail::setDefaultTransport($transport);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('noreply#bar.com', 'NoReply');
$mail->addTo('jono#gmail.com', 'jono');
$mail->setSubject('TestSubject');
$mail->send();
but it only times out, and I can't find any config options that would help.
So the question is, is it possible to send mail using Zend_Mail through a Google SMTP relay without using any login credentials, if the IP is whitelisted in the Gmail settings? If not, is there any other way to do this through the command line or another PHP library?
Try to change your $config array like this :
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'noreply#bar.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

PHP - SMTP configuration without php.ini

I am using mail() to send emails in my php application. Since I do not have access to my hosting server settings ( php.ini ), is it possible to configure the SMTP settings from my application ? So far I have found this approach
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your#gmail.com', //your gmail account
'password' => 'snip' // your password
));
but once I am not sure how to include this Mail class and second I need to do this everywhere I send mails in the app so seems not good for me.
The PHP manual says you can set everything except the path to the sendmail binary in your directory-local .htaccess files. Your sample code appears to use the PEAR::Mail extension, which may not be available on your system.

Bluehost's mail server seems not be sending my emails from Swiftmailer

I've a laravel app nad I've been testing it with gmail smtp server and It was working in my system's localhost but then I deployed it on server (blue host) and change the configuration and still the app thinks that is sending emails and it's not giving me errors but no email is delivered to corresponding email addresses....
Here's my mail.php in app folder:
return array(
'driver' => 'smtp',
'host' => 'mail.mash-up.fi',
'port' => 26,
'from' => array('address' => 'registration#mash-up.fi', 'name' => 'Admin'),
'encryption' => 'tls',
'username' => '************',
'password' => '******',
'sendmail' => '/usr/bin/sendmail -bs',
'pretend' => false,
);
where I'm doing wrong?
any help is appreciated
If you are using the BH DNS(ns1.bluehost...), then check to see that the $from address is an existing email in your BH account.
(go to your CP /domain manager and use whois info to find that out.)
or.....
maybe, you migrated the source code, but did you transfer your domain name to BH, or is it pointing to BH servers (DNS)
In that case your site is not using the BH mail servers.
example :your site content could be on BH, but if it is registered somewhere else and the DNS is not ns1.bluehost.com..etc, then your domain might be using url forwarding or framing (to bring visitors to the BH location). but your mail functions may be handled by the registrar's
hope this is not too confusing
it is also helpfull if you post your domain name here and others can help figure out as well.
Please try to check the spam folder of where your sending to. If there is nothing, make sure your "from" is truly your bluehost email account your using to send the email. If the actual sender doesn't match the "from" of the e-mail many mail clients will ignore it entirely (like hotmail), but gmail will put it in the spam folder with a warning.
The host should be your bluehost box I think. In fact on cpanel, go to email, where you create accounts. Then click on "More", select "Configure Email Client", scroll down. You will see the host name, and port.
TTL/SSL would likely need port 465, I am guessing (I use the latter, not the former like you).
Open up the laravel.logs file inside of storage > logs. It should help give you some idea of what the problem might be.

Categories