1

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?

Smern
  • 18,746
  • 21
  • 72
  • 90
  • try this http://stackoverflow.com/a/10985689/1239506 – Moyed Ansari Mar 26 '14 at 07:18
  • @MoyedAnsari, I'm not sure what you mean. My `App::uses` calls are identical to that. – Smern Mar 26 '14 at 12:17
  • I mean have you configured email settings ? – Moyed Ansari Mar 26 '14 at 12:20
  • @MoyedAnsari, I haven't done anything other than the above (which was based on [the CakeEmail page](http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#basic-usage). The link you posted does not mention email configuration/settings. Could you explain? – Smern Mar 26 '14 at 12:40

1 Answers1

3

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

Smern
  • 18,746
  • 21
  • 72
  • 90
Moyed Ansari
  • 8,436
  • 2
  • 36
  • 57
  • I saw this in the documentation, but it appears to be for sending an email **from** a gmail account that I own. What I'm wanting to do is send an email from the email address the user inserted (the `$from` parameter) **to** my email address. – Smern Mar 26 '14 at 13:00
  • 1
    yes but for that you need SMTP server configured on your machine. gmail provide free services for sending email. Here username is required just for authentication purpose. – Moyed Ansari Mar 26 '14 at 13:04
  • Okay, I will give it a try when I get home. – Smern Mar 26 '14 at 13:05
  • Okay, the email is sending now, but instead of sending from the `$Email->from`, it is sending from the gmail account. I suppose I can use the replyTo to make it so I can easily reply to whoever send it though. – Smern Mar 26 '14 at 22:02