Sunday, October 26, 2014

CakeEmail problems

I'm currently rewriting a client's web application using cakephp.  One of the pages requires sending the data in a form to the company in an email.  I'm having problems with this in my development environment:
  • Ubuntu 14.10
  • Apache2/PHP  with all the normal libraries like lib_php, mod_rewrite, etc
  • PHP 5.5
  • CakePHP 2.5.4

After poking about a bit on the web, I've seen that I have to load lib_openssl and that I should include the following line in my php.ini file.  So in /etc/php5/apache2/php.ini I've added the recommended line to the Dynamic Extensions section:

extension=php_openssl.so

I'm not sure if this is correct because Ubuntu includes php_openssl via gnutls. However, I don't know how to test this.

I've created an email.php file under app/Config with the following class definition:

class EmailConfig {
 
public $gmail = array(
 
'host' => 'ssl://smtp.gmail.com',
 
'port' => 465,
 
'username' => 'myusername@gmail.com',
 
'password' => 'mypassword',
 
'transport' => 'Smtp',
 
);
}

The username and password are copied from Thunderbird, so should be OK.

Finally, I set up a test page under app/View/Pages, called email-tester.ctp containing the code:

<?php
App::uses('CakeEmail', 'Network/Email');

$Email
= new CakeEmail();
$Email
->from(array('myusername@gmail.com' => 'My Gmail Address'))
 
->to('myemail@myemailprovider.con')
 
->subject('About')
 
->send('My message');
?>
<p>Email sent...</p>

When I try to open this page at localhost/myproject/pages/email-tester I get an error message as follows:


Error: An Internal Error Has Occurred.

Stack Trace

If anyone can decode this for me, or give me some idea as to what I should try next, I'd be very grateful.

Thanks in advance


Peter

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: