0
在codeigniter中發送和發送電子郵件時遇到問題;錯誤是 遇到PHP錯誤在codeigniter中發送電子郵件時出錯
Severity: Notice
Message: Undefined property: Asset::$email_ctrl
Filename: controllers/asset.php
Line Number: 787
Fatal error: Call to a member function send_email() on a non-object in C:\wamp\www\asset_apps\application\controllers\asset.php on line 787
請幫忙。非常感謝您的幫助
這是我的控制器;
public function tambahassetproses() {
$varkodeasset =$this->input->post('idasset');
$varassetacc =$this->input->post('idassetacc');
$varnmasset =$this->input->post('nmasset');
$variddpj =$this->input->post('iddpj');
$varidper =$this->input->post('idper');
$varlokasi =$this->input->post('idlokasi');
$varkategory =$this->input->post('idkat');
$varmacaddr =$this->input->post('macaddr');
$varssn =$this->input->post('serialnum');
$varmodel =$this->input->post('smodel');
$varmanufacture =$this->input->post('manufacture');
$varstatus =$this->input->post('status');
$licence_qty =$this->input->post('licenceqty');
if ($varstatus == 'on')
{
$varstatus = '1';
}
else
{
$varstatus = '0';
}
$vardpjdate =$this->input->post('datedpj');
$varaccdate =$this->input->post('dateacc');
$varsusut =$this->input->post('masasusut');
$varstatustrn = 'N';
$object = array (
'kodeasset' => $varassetacc,
'nama_asset' => $varnmasset,
'iddpj' => $variddpj,
'idperush' => $varidper,
'idlokasi' => $varlokasi,
'idkategory' => $varkategory,
'mac_addr' => $varmacaddr,
'serialnumber' => $varssn,
'smodel' => $varmodel,
'manufacture' => $varmanufacture,
'flagstatus' => $varstatus,
'status_trn' => $varstatustrn,
'tglperolehan' => $varaccdate,
'tglterimaasset' => $vardpjdate,
'masasusut' => $varsusut ,
'licence_qty' => $licence_qty
);
$this->db1 = $this->load->database('default', true);
$query = $this->db1->insert('tblasset',$object);
if($query)
{
$userid = $this->session->userdata('userid');
//sent email to accounting;
$query=$this->assetmodel->dataemail('tambahassetproses');
foreach ($query->result() as $row)
{
$to = $row->to_name;
$email = $row->email;
$message = $row->message_template;
$recipient_id = $row->recipient_id;
$typework = 'Input Kode Asset';
$send_email = $this->email_ctrl->send_email($to, $email, $message,$recipient_id,$typework, $userid);
if ($send_mail == FALSE) {
echo 'Could not Send Email';
} else {
echo 'Congrat!! Send Email Success';
}
}
$data['username'] = $this->session->userdata('username');
$data['description'] = $this->session->userdata('userdescr');
$data['asset'] = $this->assetmodel->mstasset()->result_array();
$data['pesan'] = "sukses isi data";
$data['content'] = 'master/master_asset';
$this->load->view('template', $data, FALSE);
}
else
{
$data['username'] = $this->session->userdata('username');
$data['description'] = $this->session->userdata('userdescr');
$data['pesan'] = "gagal isi data";
$data[content] = 'master/master_asset';
$this->load->view('template', $data, FALSE);
}
}
public function send_email($fr_email, $to_email, $message, $recipient_id, $typework, $userid) {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]', // change it to yours
'smtp_pass' => 'yul14nt1', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
'crlf' => "\r\n",
'newline' => "\r\n"
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($fr_email); // change it to yours
$this->email->to($to_email);// change it to yours
$this->email->subject('no.reply:need action on asset apps worklist');
$message= /*-----------email body starts-----------*/
'Hi ' . $to_email . ',' .
'Ada Worklist yang harus kamu complete di Web Asset Applikasi, ' . $message .'!
Silahkan Login ke :
' . base_url() . 'asset_apps/loguser' ;
/*-----------email body ends-----------*/
$this->email->message($message);
if($this->email->send())
{
//Insert Into Worklist
//get nextvalue
$varcreation_date = date('Y-m-d H:i:s');
$this->db1 = $this->load->database('default', true);
$query = $this->db->query("SELECT nextval('worklist_seq'::regclass) AS nextid");
$row = $query->row();
$worklist = array (
$id => $row->nextid;
$sender_id => $this->session->userdata('userid');
$recipient => $recipient_id;
$recipient_email => $to_email;
$typeworkdescr => $typework;
$status = 1;
$link = 'http://localhost/asset_apps/loguser';
$creation_date = $varcreation_date = date('Y-m-d H:i:s');
$user_id = $userid;
$update_date = $varcreation_date = date('Y-m-d H:i:s');
$update_user_id = $userid;
)
$this->db1 = $this->load->database('default', true);
$query = $this->db1->insert('tblasset',$worklist);
echo 'Email sent.';
return TRUE
}
else
{
show_error($this->email->print_debugger());
return FALSE;
}
}
這是我的模型:
public function dataemail($modul) {
$this->db1=$this->load->database('default', true);
return $this->db1->select('*')
->from('tblemail')
->get();
}