CakePHP2.x:邮件设置

官方配置文档:
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html

1. 复制D:\work_documents\htdocs\app\Config\email.php.default,另存为D:\work_documents\htdocs\app\Config\email.php

2.修改email.php
public $smtp = array(
		'transport' => 'Smtp',
		'from' => array('[email protected]' => '我的默认标题'),//默认的发送邮件邮箱,和发送人的别名
		'host' => 'smtp.exmail.qq.com',//发送邮件的服务器,这里是腾讯的企业邮箱
		'port' => 25,
		'timeout' => 30,
		'username' => '[email protected]',//发送邮件的账户,更上面设定是一样的
		'password' => 'xxxxxx',//发送邮箱的密码
		'client' => null,
		'log' => false,
		//'charset' => 'utf-8',
		//'headerCharset' => 'utf-8',
	);


3.发送邮件代码
        App::uses('CakeEmail', 'Network/Email');
        $email = new CakeEmail();
        $email->config('smtp');//这个是必须的,告诉使用第2步的配置来发送
        $email->from(array('[email protected]' => '这封邮件的标题'));//如果这里没有被设定,那么会使用第2步设定的信息和标题
        $email->to('[email protected]');//这里是接收这封邮件的邮箱
        $email->subject('About2');//邮件的标题
        $email->send('My message');邮件的内容



如果不想设定第二步,那么每次发送之前要做配置:
App::uses('CakeEmail', 'Network/Email');
        $email = new CakeEmail();
        //$email->config('smtp');
        $email->config(array(
            'transport' => 'Smtp',
		'from' => array('[email protected]' => '我的默认标题'),//默认的发送邮件邮箱,和发送人的别名
		'host' => 'smtp.exmail.qq.com',//发送邮件的服务器,这里是腾讯的企业邮箱
		'port' => 25,
		'timeout' => 30,
		'username' => '[email protected]',//发送邮件的账户,更上面设定是一样的
		'password' => 'xxxxxx',//发送邮箱的密码
		'client' => null,
		'log' => false,
		//'charset' => 'utf-8',
		//'headerCharset' => 'utf-8',
        ));
        //$email->from(array('[email protected]' => '我的邮件2'));
        $email->to('[email protected]');//这里是接收这封邮件的邮箱
        $email->subject('About2');//邮件的标题
        $email->send('My message');邮件的内容

你可能感兴趣的:(cakephp)