Question

I'm pretty new to CakePHP and this is my first attempt setting up an email form.

Keeping the example simple:

<?php
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
class EmailController extends AppController {

    public function send_email($from, $subject, $message) {
        $Email = new CakeEmail();
        $Email->from($from)
        ->to('[my personal email]')
        ->subject($subject);
        if($Email->send($message)) {
            $result = 'Your email has been sent.';
        } else {
            $result = 'Your email failed to send.';
        }

        $this->set('result', $result);
        $this->set('params', '('.$from.'|'.$subject.'|'.$message.')');
    }
}

send_email.ctp

<?php echo $result;?>
<br>
<?php echo $params;?>

I'm getting "Your email has been sent.", the $params look as I expect, and I am not seeing any errors... but I'm not getting the email. Any idea why this might happen?

Was it helpful?

Solution

Before this you need to define Email configuration in email.php under Config folder

Here we have gmail configuration for example

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

then you can use this setting in controller like

$Email= new CakeEmail('gmail');

Inshort you have to configure SMTP according to requirement. I hope this will be handy for you. Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top