truonghust918
truonghust918

Reputation: 55

Cannot send email in CakePhp

I make API for send email using cakephp. This is my code:

        App::uses('CakeEmail', 'Network/Email');
        $this->autoLayout = false;
        $this->autoRender = false;
        $data = $this->request->data;
        $title = $data['title'];
        $content = $data['content'];   
        $Email = new CakeEmail('smtp');
        $Email->from('[email protected]');
        $Email->to($data['email'][0]);

        $Email->subject($title);

        $Email->send($content);

And it show error php_network_getaddresses: getaddrinfo failed: No address associated with hostname. Please help me in this case

Upvotes: 1

Views: 161

Answers (1)

AD7six
AD7six

Reputation: 66208

The error message indicates that php cannot communicate with the host hostname - this comes from the configuration for that class:

class EmailConfig {
    public $smtp = array(
        'host' => 'hostname', // <---
        ...
    );
}

Either it's badly configured, or the domain name does not resolve.

Upvotes: 1

Related Questions