welcome.php文件
function formData(){
if (empty($this->input->post('checkprocess'))) {
$email_config = Array(
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$admin_email ='rockpokhrel@gmail.com';
$name = $this->input->post('full_name');
$email = $this->input->post('email');
$message = "Dear Admin, <br/>" .
"Contact Information of Users:" .'<br/>'.
"<b>Name</b> :- " . $this->input->post('full_name') .'<br/>'.
"<b>Email:-</b> " . $this->input->post('email') .'<br/>'.
"<b>Contact Number:-</b> " . $this->input->post('mob_num') .'<br/>'.'<br/>'.
"<b>Address:-</b> " . $this->input->post('address') .'<br/>'.'<br/>'.
"<b>Message:-</b> " . $this->input->post('message');
$this->load->library('email', $email_config);
$this->email->set_newline("\r\n");
$this->email->from($this->input->post('email'), $this->input->post('name'));
$this->email->to($admin_email);
$this->email->subject("Public Contact/Feedback");
$this->email->message($message);
if ($this->email->send()) {
echo "<meta http-equiv=REFRESH CONTENT=0;url='".base_url()."'>";exit();
$this->db->insert('tbl_contactusform',$email_config);
redirect(base_url());
}
}
}
library / email.php文件
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.example.com',
'smtp_port' => 465,
'smtp_user' => '**********@gmail.com',
'smtp_pass' => '************',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$htmlContent = '<h1>Sending email via SMTP server</h1>';
$htmlContent .= '<p>This email has sent via SMTP server from CodeIgniter application.</p>';
$this->email->to('**********@gmail.com');
$this->email->from('**********@gmail.com','MyWebsite');
$this->email->subject('How to send email via SMTP server in CodeIgniter');
$this->email->message($htmlContent);
$this->email->send();
我想在网站上添加电子邮件功能,但我得到了这个堆栈跟踪:
遇到严重错误:通知
消息:未定义属性:欢迎:: $ email
文件名:MX / Loader.php
行号:304
Backtrace:
错误和
遇到未捕获的异常类型:错误
消息:在null
上调用成员函数initialize()文件名:E:\ xampp \ htdocs \ website \ application \ libraries \ email.php
行号:17
我是CodeIgniter的初学者。
答案 0 :(得分:1)
要使用电子邮件类,您必须使用
加载库$this->load->library('email');
或
在application/config/autoload.php
$autoload['libraries'] = array('email');