0

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' => 'my_email@gmail.com',
        'password' => 'password',
        'client' => null,
        'tls' => true,
    ],
],

'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => 'my_email@gmail.com',
    ],
],

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?

Community
  • 1
  • 1
Rémi
  • 3,867
  • 5
  • 28
  • 44
  • You better refer to the docs: **[http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports](http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports)** – ndm Mar 26 '15 at 05:22
  • @ndm that exactly the page I was using to try to setup my email sending. thanks – Rémi Mar 26 '15 at 11:18

2 Answers2

0

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: webmaster@example.com";

The receiving party will see the email was sent from webmaster@example.com. 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

  • 1
    Why would there be a need for a mail server when using an external SMTP? CakePHPs SMTP adapter will communicate directly with the configured external server. ps, XAMPP for Windows ships with Mercury, OSX has Postfix included out of the box, and Linux, well, many distributions ship with some sort of mailserver too. – ndm Mar 26 '15 at 05:19
0

Try with

 'EmailTransport' => [
    'default' => [
        'className' => 'Smtp',
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'timeout' => 30,
        'username' => 'my_email@gmail.com',
        'password' => 'password',
        'tls' => true, // This may not be needed
    ],
],
  • Thank you, I changed my config file to this one and I still don't have any mail in my mailbox and no error – Rémi Mar 26 '15 at 11:19
  • No error and no email. Tonight I will have a look a it with the debugger included. – Rémi Mar 26 '15 at 13:43