Bogdan
Bogdan

Reputation: 865

cakephp 2.0 smtp email

I am trying to send a email message using CakePhp 2.0. in my controller i use this code (i know it's fine, i took it from the cookbook) :

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail("myConfig");
$email->from(array('[email protected]' => 'From Example'));
$email->to($to);
$email->subject($msgtitle);
$ok = $email->send($content);

and in app/config/email.php i have this config :

<?php
class EmailConfig {
    public $myConfig = array(
        'host' => 'mail.myServer.com',
        'port' => 587,
        'username' => 'mYaccount',
        'password' => 'secret',
        'transport' => 'Smtp'
    );
}
?>

the problem is the server answers with :

SMTP Error: 530 5.7.0 Must issue a STARTTLS command first.

the account name is correct, as is the password. The config works when loading it up in thunderbird, the connection to the smtp server is set up as :

server name : mail.myServer.com
port : 587
connection security : STARTTLS
authentication : normal password
user name : mYaccount

Upvotes: 2

Views: 9485

Answers (6)

Prem Mahato
Prem Mahato

Reputation: 21

public $smtp = array(
        .................,
        'tls'   =>  true
    );

Upvotes: 2

Aditya P Bhatt
Aditya P Bhatt

Reputation: 22071

Below code is working for me over GoDaddy server using CakePHP SMTP Email:

Email.php file inside config folder - CakePHP 2.4 MVC version:

    // for Live Server GoDaddy.com domain
    public $smtp = array(
        'transport' => 'Smtp',
        'host' => 'ssl://smtpout.asia.secureserver.net', <-- important
        'port' => 465, <-- important
        #'timeout' => 30,
        'username' => '[email protected]',
        'password' => 'password',
        #'tls' => false,
        #'log' => false,
        'charset' => 'utf-8',
        'headerCharset' => 'utf-8',
    );

And here is the controller file code below:

    // Controller Code to Send Actual Email
    // email configuration
    $Email = new CakeEmail('smtp');
    $Email->from(array('[email protected]' => 'App Name'))
        ->sender('[email protected]', 'App Name')
        ->to(array($email))
        ->bcc(array('[email protected]'))
        ->subject('Test Email from GoDaddy')
        ->emailFormat('both')
        ->send($hash.'<br><strong>My</strong> message 45 قبل الميلاد، مما يجعله أكثر من');

Hope it helps !

Thanks

Upvotes: 1

Evin1_
Evin1_

Reputation: 12866

Make sure your

php_openssl.dll

extension is running.

You can check it on thephp.ini file.

If you are using XAMPP php.ini should be on C:\xampp\php

   php.ini:

;extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll  ; Use with Oracle 11gR2 Instant Client
extension=php_openssl.dll
;extension=php_pdo_firebird.dll

Upvotes: 0

Ken
Ken

Reputation: 1

Give the following a try:

 <?php
class EmailConfig {
    public $myConfig = array(
        'host' => 'ssl://mail.myServer.com',
        'port' => 465,
        'username' => 'mYaccount',
        'password' => 'secret',
        'transport' => 'Smtp'
    );
}
?>

Upvotes: 0

Chuck Burgess
Chuck Burgess

Reputation: 11574

Are you certain your SMTP supports tls? Try sending the ehlo command:

telnet 1.2.3.4 25
ehlo testing

You should see something like:

250-STARTTLS

in the list.

If you see it, then it is most likely not enabled. You will need to enable it. If you do not see it, you will need to add it.

Upvotes: 2

entropid
entropid

Reputation: 6239

From the CakePHP Cookbook:

You can configure SSL SMTP servers, like GMail. To do so, put the 'ssl://' at prefix in the host and configure the port value accordingly. Example:

class EmailConfig {
public $gmail = array(
    'host' => 'ssl://smtp.gmail.com',
(...)

Upvotes: 0

Related Questions