0
votes

I'm developing a website using cakephp 3.0 and I'm trying to send a confirmation email from my localhost (xampp) by using gmail server. I can tell for sure that my controller function is executed but nothing happen, no email, no error, no log, etc.

I read here that you can't send email from localhost (hence trying to use gmail to send it)

Here my config in the app.php

'EmailTransport' => [
    'default' => [
        'className' => 'Mail',
        // The following keys are used in SMTP transports
        'host' => 'smtp.gmail.com',
        'port' => 587,
        'timeout' => 30,
        'username' => '[email protected]',
        'password' => 'password',
        'client' => null,
        'tls' => true,
    ],
],

'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => '[email protected]',
    ],
],

And here is my function where I try to send the email.

public function send()
{
    $email = new Email('default');
    $email->to('other_email@gmail')
          ->subject('About')
          ->message('blablabla');

    if($email->send())
    {
        return $this->render('confirmation');
    }
}

I can tell for sure this code is executed because the confirmation view is rendered after I press send.

What am I missing to send the email?

2
@ndm that exactly the page I was using to try to setup my email sending. thanks - Rémi

2 Answers

0
votes

You won't be able to send an email without a server that has a mail server. This unfortunately, is not included with xampp. If you're trying to send emails from your Gmail using the "From" header, I think that you are misunderstanding the use of the "From" parameter. The "From" is really only for the receiving parties end.

Example:

If you have:

$headers = "From: [email protected]";

The receiving party will see the email was sent from [email protected]. However, the email is actually still sent from YOUR mail server (so on localhost, you would be unable to do so, as it does not have a mail server).

For more information on sending emails with PHP, go to http://www.w3schools.com/php/func_mail_mail.asp

0
votes

Try with

 'EmailTransport' => [
    'default' => [
        'className' => 'Smtp',
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'timeout' => 30,
        'username' => '[email protected]',
        'password' => 'password',
        'tls' => true, // This may not be needed
    ],
],