。私はテンプレートと再利用可能な電子メールセットアップ機能を使用しています。ここに私の作業コードのコピーがあります:
// 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'=>'[email protected]',
'password'=>'secret',
);
$this->Email->delivery = 'smtp';
//$this->Email->delivery = 'debug';
$this->Email->from = 'Username <[email protected]>';
$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, '[email protected]', '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
魅力的なように動作します –