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.
Related
I have this weird problem. I have setup my PHP app to send email to users, for now it is using gmail. There is no problem sending mail from my machine. But when my colleague in Japan tried my app, it doesn't send the mail. In the logs, it says that the app failed to authenticate.
'driver' => 'smtp',
'smtp' => array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'test.email#gmail.com',
'password' => 'password',
'timeout' => 5,
),
'newline' => "\r\n"
He is running the app in his machine, not from a remote server.
Google might have blocked your login because it was deemed as suspicious. (https://support.google.com/accounts/answer/6063333?hl=en)
You might want to login to this account and navigate to https://security.google.com/settings/security/activity and allow blocked device to continue.
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);
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.
I'm develop a website using Laravel 4.1. I config my email system and send email successfully on built-in server localhost:8000. But when I host the web on a shared hosting, it always tell: Swift_TransportException
Failed to authenticate on SMTP server with username "email#domain.com" using 2 possible authenticators
I don't know what the reason is? I've search on this site but no solution works.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'email#gmail.com', 'name' => 'Test email'),
'encryption' => 'ssl',
'username' => 'your_gmail_username',
'password' => 'your_gmail_password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I also used my our domain's email but it doesn't work neither. Hope for help.
In my case, I had a Cpanel dedicated server. My host informed me that exim mail server was failing and restarting a couple times a day.
It looked like all connection threads were being used up and then locked until it restarts.
My host added another 100 connection threads to the pool. Most probably this help you as well.
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.