Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send smtp mail in cakephp 2

What I did

    public $smtp = array(
        'transport' => 'Smtp',
        'from' => array('[email protected]' => 'test'),
        'host' => 'mail.mydomain.com',
        'port' => 80,
        'timeout' => 60,
        'username' => '[email protected]',
        'password' => 'me123',
        'client' => null,
        'log' => false,
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    );

    $email    = new CakeEmail('Smtp');
    $result   = $email->template('welcome_mail','default')
                       ->emailFormat('html')
                        ->to($to_email)
                        ->from('[email protected]')
                        ->subject('Welcome')
                        ->viewVars($contents);

    if($email ->send('Smtp'))
    {   
        echo ('success');

    }

what I am doing wrong here? Please can anyonce explain smtp settings here? what is host,username,password,client?

Please guide me what is host

which username and password I have to set here

like image 828
anytime Avatar asked Oct 05 '13 06:10

anytime


People also ask

How can I send email in cakephp 2?

Sending messages quickly Example: CakeEmail::deliver('[email protected]', 'Subject', 'Message', array('from' => '[email protected]')); This method will send an email to [email protected], from [email protected] with subject Subject and content Message. The return of deliver() is a CakeEmail instance with all configurations set.

How can I send email in cakephp 3?

After you've loaded Email , you can send an email with the following: $email = new Email('default'); $email->from(['[email protected]' => 'My Site']) ->to('[email protected]') ->subject('About') ->send('My message');


1 Answers

I would add the Email Config to your email.php file located in /app/Config/email.php , if it doesn't exist copy email.php.default to email.php, Change the smtp settings there

public $smtp = array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'username' => '[email protected]',
    'password' => 'secret'
);

At the top of your Controller above class Controller extends AppController add,

App::uses('CakeEmail', 'Network/Email');

Then to send an email, try

$Email = new CakeEmail();
$Email->from(array('[email protected]' => 'My Site'))
    ->to('[email protected]')
    ->subject('About')
    ->send('My message');

To test emails what I usually do is send them to the Cake Logs,

**In /app/Config/email.php, include: ( The log output should be /app/tmp/logs/debug.log )

public $test = array(
  'log' => true
);

Also doing this add 'test' to your $Email variable like,**

$Email = new CakeEmail('test');
like image 148
Brett Stewart Avatar answered Nov 01 '22 13:11

Brett Stewart