我目前正在使用Codeigniter进行项目。应用程序以不同的目的发送邮件。目前,我在我的模型中有这个代码。我想知道如何重用以及在不重新初始化电子邮件设置的情况下重用此代码的最佳方法是什么。
$subject = 'Password Reset';
$email['userinfo']=trim(ucwords($input['email'])); //user's email
$app_email = 'myemail@domain.com';
$app_password = 'password';
$message = $this->load->view('forgot_mail',$email,TRUE); //message content
/* CONFIGURE EMAIL SETTINGS */
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.mail.domain.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = $app_email;
$config['smtp_pass'] = $app_password;
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$this->load->library('email', $config);
$this->email->initialize($config);
答案 0 :(得分:1)
在config
中创建一个名为mail.php
(或email.php
)的application/config/
文件。然后像这样在配置文件中管理您的设置..
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE@gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
您只能设置必需的配置项。
然后在Controller
。
加载电子邮件库:
$this->load->library('email');
并将主题,消息,来自等等的邮件设置为...
$subject = 'Password Reset';
$email['userinfo']=trim(ucwords($input['email'])); //user's email
$app_email = 'myemail@domain.com';
$app_password = 'password';
...........//more
在这里工作正常。
希望它有效。