tags:

views:

351

answers:

2

I've been successfully using CakePHP's email component to send my email but due to restrictions I now need to set it up to use a smtp relay server and I'm getting some strange results.

Here is my code:

$this->Email->to = $user['User']['username'].' <'.$user['User']['email'].'>';
$this->Email->subject = 'MyWebsite.com – Please confirm your email address';
    $this->Email->from = 'MyWebsite.com <[email protected]>';
    $this->Email->template = 'user_confirm';
    $this->Email->sendAs = 'html';
    $this->Email->smtpOptions = array(
        'timeout' => '30',
        'port' => '25',
        'host' => 'mail.myrelayserver.com',
        'username' => 'USERNAME',
        'password' => 'PASSWORD'
    );
    $this->Email->delivery = 'smtp';
    if ($this->Email->send()) {
        return true;
    } else {
        echo $this->Email->smtpError;
    }

Now whenever I try and send this email, the send fails and I get the following ouput from $this->Email->smtpError:

14.2/Kp; Sun, 14 Feb 2010 19:11:07 GMT

Any ideas?

A: 

"14.2/Kp; Sun, 14 Feb 2010 19:11:07 GMT" is a part of sendmail's 'greeting' message. Perhaps connection is dropped before authorization? Did you try connecting with netcat or telnet to your relay?

Qwerty
I just successfully connected with telnet and got the full sendmail greeting this time, so it looks like you were right
gomezuk
A: 

Fixed.

The problem was something to do with my smtp relay server not accepting connections from my cloud server. As soon as I added the following lines to the sendmail configuration file, email started coming through.

MASQUERADE_AS(`mydomain.com')dnl FEATURE(masquerade_envelope)dnl

I hope this helps somebody else :)

gomezuk