Send unauthenticated Google SMTP message using Zend_Mail - php

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);

Related

Zend 2 smtp Mail not working on godaddy

I have successfully configured the smtp connection on local but when i am using it on live go-daddy its throwing e error that connection has been refused.
$smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
$smtpOptions->setHost('smtp.gmail.com')
->setConnectionClass('login')
->setName('smtp.gmail.com')
->setConnectionConfig(array(
'username' => 'XXXXXX#gmail.com',
'password' => 'XXXXX!',
'ssl' => 'tls',
))
->setPort('465');
$transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
i have tried port 587 also. Would be great if someone could guide me how to solve this . Stuck over this from few days . thanks
See configuration of your godaddy mail server. I use following host for godaddy account -
mail domain: smtpout.secureserver.net
host: 173.201.193.101
port: 25
Above configuration works fine for me. Please use your own username and password that is not mention here. Also I use SMTP for mail transport.

Send Email using Outlook through PHP Pear

I'm trying to send an email using PHP Pear. It works when I send email using Gmail with this settings:
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'username#gmail.com',
'password' => 'password!2016'
));
But before I make this work, I have to "allow less secure apps" to access my account, which you can read here on how to do it.
I tried to use an Outlook account with this settings:
$smtp = Mail::factory('smtp', array(
'host' => 'tls://smtp.office365.com',
'port' => '587',
'auth' => true,
'username' => 'email#domain.org',
'password' => 'greatPasswordComesWithGreatResponsibilities'
));
but I get this error:
Failed to connect to ssl://smtp.office365.com:587 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.office365.com:587 (Unknown error) (code: -1, response: )]
I checked the official article by Microsoft regarding their SMTP settings. So I thought I have the right settings, but it's not working.
Am I missing something? Why do I get this error? Is there a setting I have to configure in my outlook account, like with the Gmail, before a third party app be allowed to send email?
This may not help but the title of your post just said Outlook account but the link and smtp settings refer to Office365 for Business accounts. I can't shed any light on the business account but if you actually have a personal Outlook.com account the settings are different. And, there is an option on the account you must change to enable pop/smtp access as you did with gmail.
The official Microsoft article is:
https://support.office.com/en-us/article/Add-your-Outlook-com-account-to-another-mail-app-73f3b178-0009-41ae-aab1-87b80fa94970?ui=en-US&rs=en-US&ad=US&fromAR=1
But, the summary is the smtp server is smtp-mail.outlook.com and to enable pop/smtp in your Outlook account look for Options > Managing your account > Connect devices and apps with POP.
Update:
If you are actually using business account, you should check this post which claims to have it working: https://stackoverflow.com/a/26004690/2891120
The key item in his code is he doesn't have "tls://" in front of the host name. I have a consumer outlook account and get a similar socket failure to you with tls:// prefix. If I remove that prefix I get much farther (set debug=true in factory) but fail later with an auth failure. Using 5.2.16 PHPMailer instead I successfully send mail but the headers leave me worried about spam rejection rates (no DKIM, SPF was softfail for my AWS entity, warning about -f, and others). And, the email did end up in the junk folder of my other test recipient #outlook.com. But I digress.

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.

CakePHP Cake Email SMTP Gmail

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.

Zend Mail Gmail SMTP

Hi I'm trying to send some emails via gmail from the Zend_Mail module.
This is my code:
$config = array(
'ssl' => 'tls',
'port' => 587,
'auth' => 'login',
'username' => 'webmaster#mydomain.com',
'password' => 'password'
);
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Error:
Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in /library/Zend/Mail/Protocol/Smtp.php on line 206
Unable to connect via TLS
I tried telling my hosting provider to enable the openssl.dll in phi.ini
But they say that isn't necessary since the server is in Linux and it doesn't need to enable the openssl.dll to work with TLS or SSL.
Is my hosting provider wrong or I'm I doing something wrong in my code.
Thanks in advance
Fabian
openssl.dll is the windows openssl extension.
On Linux you need to compile PHP with OpenSSL support.
http://www.php.net/manual/en/openssl.installation.php
You need OpenSSL for PHP sockets and stream functions to use TLS. Zend uses these functions and thus require the same.
I was having a similar problem here is what worked;
Using Zend mail transport and yahoo smtp:
$mailhost= 'smtp.example.com';
$mailconfig = array(
'auth' => 'login',
'username' => 'me#example.com',
'password' => 'topsecret',
'port' => '465',
'ssl' => 'ssl'
);
$transport = new Zend_Mail_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);
This produced an error: "Permission denied" and no mail was sent. After three weeks of trying all solutions I could find the one that worked was changing:
$transport to;
$transport = new Zend_Mail_Transport_Sendmail('-fsupport#website.com',$mailhost, $mailconfig);
works as expected...
It's very comfortably to use Zend_Mail::setDefaultTransport method
Try setting ssl:// as prefix for the hostname and use 465 as port.
after hours of troubleshooting, changing
'ssl' => 'tls'
to
'ssl' => 'ssl'
worked for me. It was working fine in previous server. After moving to new server, tls error statrted.

Categories