我正在使用以下代码在codeigniter中发送电子邮件,并且想知道放置代码的最佳位置在哪里。用codeigniter发送电子邮件|在哪里存储代码?
它目前存在于我的控制器中,但体积庞大,我相信它有一个更好的地方。
我的电子邮件代码的工作方式是我在电子邮件中设置我想要的变量,然后将它们输入到模板中并发送。
我将在我的网站上发送多个电子邮件,因此我应该在哪里放置代码和方式。 (图书馆助手?)
代码:
$this->load->library('email');
$this->email->initialize();
$this->email->from('[email protected]', 'domainy');
$email = $this->input->post('email_address');
$this->email->to($email);
$this->email->subject('Great question. We will answer it as soon as we can');
$emaildata['title'] = 'Company - Ask us a question';
$emaildata['preheader_teaser'] = 'Your question has been received and we will be answering it shortly. Please keep an eye on your inbox for our response.';
$emaildata['preheader_links'] = ' <em><b>Do not reply to this email</b></em>';
$emaildata['header_image'] = 'http://www.domain.com/assets/img/logo.png';
$emaildata['body_content'] = '
<h1>Hi '.$this->input->post('first_name').',</h1>
<h2 style="color:#ccc !important;">Great question!</h2>
<p>Your question has been submitted to our consultants and received with thanks. We will answer you question as soon as we can.</p>
<p>Response generally takes within 24 to 48 hours and will be in the form of an email or (if provided) a telephone call.</p>
<p>We will handle your question in the most efficient way possible and get back to you with an answer as soon as we can.</p>
<p>Have a super day!</p>
<h4 style="color:#1a3665 !important;">Your question to us:</h4>
'.$this->input->post('question').'
';
$emaildata['footer_social_links'] = 'Follow us on ';
$emaildata['footer_copyright'] = 'Copyright © domain MMXI, All rights reserved.';
$emaildata['footer_description'] = '"Impartial, help and assistance, as and when you need it"';
$emaildata['footer_mailing_address'] = '[email protected]';
$emaildata['footer_utility_links'] = '<a href="http://www.domain.com/">www.domain.com</a>';
$emaildata['footer_rewards'] = ' ';
$emailbody = $this->load->view('email/templates/simple-basic',$emaildata,true);
$this->email->message($emailbody);
$this->email->send();