我目前正在使用 gmail 帐户发送出站邮件。我正在使用模板和可重复使用的电子邮件设置功能。这是我的工作代码的副本:
// app/controllers/users_controller.php
function sendemail($subject, $body, $to, $template) {
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'username@domain.com',
'password'=>'secret',
);
$this->Email->delivery = 'smtp';
//$this->Email->delivery = 'debug';
$this->Email->from = 'Username <username@Domain.com>';
$this->Email->to = $to;
$this->Email->subject = $subject;
$this->set('body', $body);
$this->set('smtp_errors', $this->Email->smtpError);
$this->Email->send($content, $template);
}
// app/controllers/users_controller.php
// Excerpt from new user method in users controller:
function add() {
// ...other stuff
$body['user'] = $user['User']['username'];
$this->sendemail('Domain.com New User Signup!', $body, 'destination@Domain.com', 'newuser');
// ...other stuff
}
// app/views/elements/email/text/newuser.ctp
Everyone,
Another new user just signed up for Domain. Stats below:
User: <?php echo $body['user'] . "\r\r"; ?>
Just thought you'd like to know :)
-Janet