とりあえずテスト。たぶん日本語は通らない。さくらインターネットにあるCakePHPからCoreserverのメールアカウントに接続してSMTP送信するテスト。
views/elements/email/text/test.ctp と views/elements/email/html/test.ctp を作成。
通常のViewファイルと同様にメッセージ本文を作る。ここではTESTとだけ書く。
views/layouts/email/text/default.ctp を作成
<?php echo $content_for_layout; ?>
スポンサードリンク
views/layouts/email/html/default.ctp を作成
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <body> <?php echo $content_for_layout; ?> </body> </html>
views/tests/index.ctp を作成
TEST <?php echo $smtp_errors; ?>
controllers/tests_controller.php を作成
var $components = array('Email');
function index() {
$this->Email->from = 'display_name <[email protected]>';
$this->Email->to = 'display_name <[email protected]>';
$this->Email->subject = 'Test';
$this->Email->sendAs = 'text'; // text, html, both
$this->Email->template= 'test'; //test.ctp
$this->Email->smtpOptions = array(
'port' => '25', // 25, 587
'timeout' => '30',
'host' => 'mail.your.host',
'username' => '[email protected]',
'password' => 'PASSWORD'
);
$this->Email->delivery = 'smtp';
$this->Email->send();
$this->set('smtp_errors', $this->Email->smtpError);
}
とりあえず送信できたので今日はここまで。


コメント