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 <noreply@MyWebsite.com>';
$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?
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 🙂