I found myself unable to send mails since I upgraded to php5.6.
$to = "Test1 <*******#gmail.com>";
$body = "Hi,\n\n this is just test email";
$headers = array(
'From' => '*******#gmail.com',
'To' => $to,
'Subject' => 'test email'
);
$smtp = Mail::factory('smtp', array(
'host' => 'smtp.sendgrid.com',
'port' => '587',
'auth' => 'login',
'username' => '*****',
'password' => '*****',
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo $mail->getMessage();
} else {
echo "<p> Message successfully sent!</p>";
}
login authentication failure [SMTP: STARTTLS failed (code: 220, response: Begin TLS negotiation now)]
If I use my Gmail account with this code, i get an error too
$smtp = Mail::factory('smtp',array (
'host' => 'ssl://smtp.googlemail.com',
'port' => '465',
'auth' => 'login',
'username' => '******#gmail.com',
'password' => '*******'
));
authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14 Please log in via your web browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/answer/78754 jz4sm22875767wjb.16 - gsmtp)]
I have an oid application running with ZF1, and I found that there was a problem on this call Zend_Mail_Protocol_Smtp :
stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)
I've read that some changes had been made in php 5.6 concerning OpenSSL, but I don't know what changes I need to do.
I had the same trouble and stumbled upon the solution, and these are clearly related to changes in PHP 5.6 (which I'm not all together happy about).
The verify_peer and verify_peer_name are now by default set to true - requiring an extra level of security between the two machines involved in a streamed port. I don't want this when I'm dealing with SMTP, the STARTTLS encryption is enough for me. So turn these off I added some code to the Net/SMTP.php file
$options = array('ssl' => array('verify_peer_name' => false, 'verify_peer' => false));
$result = $this->_socket->connect($this->host, $this->port, $persistent, $timeout, $options);
The socket timeout default specified in php.ini is not being used by this function. So I changed the default in 'smtp.php' to:
$timeout = 60; // previously null;
Hope that helps somebody else. Cheers Murray
I know that this question is kinda old but I will leave the answer here, maybe someone else will find it useful: https://stackoverflow.com/a/34090707/5639805
Related
I had written following code to send email.
static function sendEmail($email,$data,$type){
$Email = new CakeEmail();
$Email->config('general');
switch($type){
case 1:
$Email->template('confirmation_free', null);
$Email->subject('Confirmation of registration with XXXXXXXXXXXXX');
$Email->viewVars(array('Email'=>$data["Email"],'full_name'=>$data['full_name'],'Id'=>$data['Id'],'url'=>$_SERVER['SERVER_NAME'], 'password'=>$data['password']));
break;
case 2:
$Email->template('group-invite', 'default');
$Email->subject('XXXXXXXX Group Invite - Notification');
$Email->viewVars(array('Email'=>$data["Email"],'Username'=>$data['Username'],'Id'=>$data['Id'],'url'=>$_SERVER['SERVER_NAME']));
break;
case 3:
$Email->template('forgot_password', null);
$Email->subject('XXXXXXXX - Forgot Password');
$Email->viewVars(array('Email'=>$data["Email"],'Key'=>$data['Key'],'url'=>$_SERVER['SERVER_NAME'],'Id'=>$data['id']));
break;
}
$Email->to($email);
if($Email->send())
return true;
else
return false;
}
with following sendgrid smtp settings.
public $general = array(
'transport' => 'Smtp',
'from' => array('XXXXX#XXXXXXX' => 'XXXXXX Administrator'),
'host' => 'smtp.sendgrid.net',
'port' => 587,
'timeout' => 30,
'username' => 'XXXXXXX',
'password' => 'XXXXXX',
'client' => null,
'log' => false,
'emailFormat' => 'html'
);
It was working perfectly fine on my local and dev server. But after we installed SSL on the dev server, it started throwing following error "SMTP server did not accept the password "
Please note that I'm using a sendgrid free account. Do I need a paid account to send emails from a server with SSL?
You need to either use the tls option in your CakeEmail config or prefix the host with ssl:// https://book.cakephp.org/2.0/en/core-utility-libraries/email.html
Xylon, Please try this.
In Email.php
public $smtp = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'your email',
'password' => 'password',
'transport' => 'Smtp',
'log' => true,
'auth' => true,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
$Email = new CakeEmail('smtp'); // In Controller where you want send mail
$Email->viewVars(array("data" => $data));
$Email->template($template)
->emailFormat('html')
->to($reciever)
->from(array($mail_from => "Ecotrak"))
->subject($subject)
->send();
I hope this will resolve problem.
Email could not be sent: SMTP server did not accept the password. See trace
If you are facing that issue and your check everything is fine there is no issue anywhere but you still facing that issue.
Just do this simple process.
Go to your Google Account.
Select Security.
Go down
Click on Less Secure app access
Turn it on
Now check it... your issue will resolve
I can send email configuring smtp options from email.php file and it works fine. But I want to send emails, where the smtp options, like host, port, username and password are taken from database.
I tried to use this, but does not work, just gives an error No connection could be made because the target machine actively refused it. The smtp options are correct.
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('smtp');
$Email->smtpOptions = array(
'host' => $smtpAccount['host'],
'port' => $smtpAccount['port'],
'username' => $smtpAccount['username'],
'password' => $smtpAccount['password'],
);
$Email->to($email);
$Email->template('sending')->emailFormat('both');
$Email->subject($subject);
$Email->viewVars (
array(
'content' => $content
)
);
return $Email->send();
trying to set the host like $Email->host($smtpAccount['host']);
gives an error Call to undefined method CakeEmail::host()
Thanks
instead of $Email->smtpOptions should be used
$Email->config(array(
'host' => $smtpAccount['host'],
'port' => $smtpAccount['port'],
'username' => $smtpAccount['username'],
'password' => $smtpAccount['password'],
));
I figured that I'll try to find out if I can send mails via cmd line before writing a question here. So I followed these steps and sent an e-mail by cmd to myself and a collegue of mine who's working on the same app I am. The message from cmd line came in the format it should have come.
( internal app, should send mails only to my collegues' OUTLOOK accounts )
Everything seems to be connected fine so I figured I have an error in my cakePHP code:
Everything on mails code I have so far is this:
app/config/email.php
public $smtp = array(
'transport' => 'Smtp',
'from' => array('from#test.sk'),
'host' => 'ip_address_of_my_host',
'port' => 25,
'timeout' => 30,
'username' => 'from#test.com',
'password' => 'password',
'client' => null,
'log' => true,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
UsersController.php (test send mail function)
public function test_send_email() {
$this->autoRender = false;
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('smtp');
$email->from(array('from#test.com' => 'APP TEST'));
$email->to('me#test.com');
$email->subject('Subject of testing');
$email->send('Message of testing');
}
After 5 seconds of loading I get: SMTP Error: 504 5.7.4 Unrecognized authentication type
Solved:
I guess the authentication wasnt required on EXCHANGE, so I just removed the password parameter and works fine.
During research I found out this article, so the next step would be to contact EXCHANGE admins.
http://blogs.technet.com/b/exchange/archive/2006/12/28/3397620.aspx
I was getting the same error when using telnet on port 25. After changing to port 587, I was able to use authenticated SMTP.
I am able to send SMTP Emails from my local server machine in CakePHP while I am not able to do the same on my GoDaddy live server, in CakePHP.
Any ideas for the same?
Thanks
Answer is below as per my experience with GoDaddy:
Below code is working for me over GoDaddy server using CakePHP SMTP Email:
Email.php file inside config folder - CakePHP 2.4 MVC version:
// for Live Server GoDaddy.com domain
public $smtp = array(
'transport' => 'Smtp',
'host' => 'ssl://smtpout.asia.secureserver.net', // important
'port' => 465, // important
#'timeout' => 30,
'username' => 'no-reply#godaddy-domain.com',
'password' => 'password',
#'tls' => false,
#'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
And here is the controller file code below:
// Controller Code to Send Actual Email
// email configuration
$Email = new CakeEmail('smtp');
$Email->from(array('no-reply#godaddy-domain.com' => 'App Name'))
->sender('no-reply#godaddy-domain.com', 'App Name')
->to(array($email))
->bcc(array('xyz#xyz.com'))
->subject('Test Email from GoDaddy')
->emailFormat('both')
->send($hash.'<br><strong>My</strong> message 45 قبل الميلاد، مما يجعله أكثر من');
Hope it helps !
Thanks
Update your code to check for an error message:
if(!$this->Email->send()) {
CakeLog::write('debug', $this->Email->smtpError);
}
Then check the /app/tmp/logs/debug file on the server.
So I'm under the impression that bad things will happen if I don't use Zend_Mail_Transport_Smtp when sending lots of emails. Problem is...I can't figure out how to set it up. I am using Google Apps hosted email for my domain. So to access my email, I go to mail.mydomain.com, which takes me to a google login page.
This is the code that I am using, but it's not working.
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'webmaster#mydomain.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('mail.mydomain.com', $config);
Using "mail.mydomain.com" I get a "connection timed out" error (which makes me think its the wrong thing to use.
Using "smtp.mydomain.com" I get a "Could not open socket" error.
What am I doing wrong?
Since you are sending emails through gmail, you should use "smtp.gmail.com" and not your domain.
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'webmaster#mydomain.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Some more reference. Check the port using port scanner on remote end which are open, do a test if they reply packets, sometimes port 25 is not working so email fails, and also the SSL or TLS.
$config = array(
'ssl' => 'ssl', //TLS = tcp:// use port 25
//SSL = ssl:// use port 465 or 587
'port' => 465,
'auth' => 'login',
'username'=> 'x',
'password'=> 'b/c',
);
$tr = new Zend_Mail_Transport_Smtp('email-smtp.us-east-1.amazonaws.com', $config);
Zend_Mail::setDefaultTransport($tr);