2015-09-01 46 views
1

我一個笨項目的工作,並從PHPMailer的最後添加的版本,並使用本教程創建mailer_model奇怪的致命錯誤:調用未定義的方法的PHPMailer :: setFrom()方法使用CodeIgniter

https://phpsblog.wordpress.com/2010/02/14/phpmailer-en-codeigniter/

經過改編後,我將它用於另一個模型,並且完美。

現在對這個我有這個惱人的錯誤

enter image description here

這裏是我的自定義庫

<?php 
if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class My_PHPMailer { 
    public function My_PHPMailer() 
    { 
     require_once('PHPMailer/PHPMailerAutoload.php'); 
    } 
} 
?> 

這裏是問題的模型

<?php 
class Operators_model extends CI_Model { 

    public function send_access($idpatient, $code) 
    { 
     $this->load->model('Mailer_model'); 

     #Update code for access on patient Client 
     $data = array('Code' => $code); 
     $this->db->where('idpatients', $idpatient); 
     $this->db->update('patients', $data); 

     #Find Patient Email 
     $qry = "SELECT Email FROM patients WHERE idpatients = '$idpatient'"; 
     $result = $this->db->query($qry)->result(); 
     $emailp = $result[0]->Email; 


     $subject = 'Access to Crossover Laboratory'; 
     $message = '<p>You now can access to our laboratory results with your name and code.</p> 
     <p>Code: '. $code . ' </p> 
     <p>' . base_url() . '</p> 
     '; 
     $body2 = "You now can access to our laboratory results with your name and code.\n 
     Code: ". $code . " \n 
     " . base_url() ; 
     $body = 
     '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     <html xmlns="http://www.w3.org/1999/xhtml"> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset='.strtolower(config_item('charset')).'" /> 
      <title>'.html_escape($subject).'</title> 
      <style type="text/css"> 
       body { 
        font-family: Arial, Verdana, Helvetica, sans-serif; 
        font-size: 16px; 
       } 
      </style> 
     </head> 
     <body> 
     <p>'.$message.'</p> 
     </body> 
     </html>'; 

     $error = $this->Mailer_model->send_mail($subject, $body, $body2, $emailp, "") ; 
     return $error; 

    } 
} 

?> 

希望你可以幫我解決這個問題

UPDATE

Mailer_Model.php

<?php 
class Mailer_model extends CI_Model { 

    public function send_mail($subject, $body, $body2, $to, $attachment = "") 
    { 
     $this->load->library('My_PHPMailer'); 
     $mail = new PHPMailer(); 
     $mail->IsSMTP(); // establecemos que utilizaremos SMTP 
     $mail->SMTPAuth = true; // habilitamos la autenticación SMTP 
     $mail->SMTPSecure = "ssl"; // establecemos el prefijo del protocolo seguro de comunicación con el servidor 
     $mail->Host  = "smtp.gmail.com";  // establecemos GMail como nuestro servidor SMTP 
     $mail->Port  = 465;     // establecemos el puerto SMTP en el servidor de GMail 
     $mail->Username = "[email protected]"; // la cuenta de correo GMail 
     $mail->Password = "mypasshere";   // password de la cuenta GMail 
     $mail->SetFrom('[email protected]', 'Crossover Laboratory'); //Quien envía el correo 
     $mail->AddReplyTo('[email protected]', 'Crossover Laboratory'); //A quien debe ir dirigida la respuesta 
     $mail->Subject = $subject; //Asunto del mensaje 
     $mail->Body  = $body; 
     $mail->AltBody = $body2; 
     $destino = $to; 
     $mail->AddAddress($destino); 

     if ($attachment != "") 
     { 
      $mail->AddAttachment($attachment);  // añadimos archivos adjuntos si es necesario 
     } 

     $message = "Email Sent!"; 
     if(!$mail->Send()) { 
      $message = "Error : " . $mail->ErrorInfo; 
     } 

    } 

} 
?> 

UPDATE 2015年1月9日

現在我更新了PHPMailer的類,並改變所需的類(見上面更新後的代碼)爲PHPMailerAutoload.php

這個問題的模型正在工作,但在ot她一個也沒有了,給了我這個錯誤

enter image description here

而這裏面Patients_model問題的功能

public function Send_PDF($filename, $idreport) 
    { 
     #Send Email to client with php mailer library 
     #Check config.php on config folder for credentials 
     $this->load->library('email'); 
     $this->load->model('Mailer_model'); 

     $details = $this->ReportDetails($idreport); 
     $patientDetails = $this->PatientDataById($details[0]['idpatients']); 
     $to = $patientDetails[0]['Email']; 
     $subject = 'Crossover Report'; 
     $message = 'Attached is the Report Requested'; 
     $body2 = $message; 
     $body = 
     '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     <html xmlns="http://www.w3.org/1999/xhtml"> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset='.strtolower(config_item('charset')).'" /> 
      <title>'.html_escape($subject).'</title> 
      <style type="text/css"> 
       body { 
        font-family: Arial, Verdana, Helvetica, sans-serif; 
        font-size: 16px; 
       } 
      </style> 
     </head> 
     <body> 
     <p>'.$message.'</p> 
     </body> 
     </html>'; 
     $emailresp = $this->Mailer_model->send_mail($subject, $body, $body2, $to, $filename) ; 
     return $emailresp; 
    } 
+0

檢查此[鏈接](http://stackoverflow.com/questions/2509145/phpmailer - 調用undefined-method-phpmailersetfrom) – Saty

+0

@Saty謝謝,幾個小時前已經檢查過幾次,我正在使用最後一個庫,正如我在這個問題上說的那樣,它在一個模型,並在其中的一個問題不 –

+2

你在你的控制器調用phpmailer庫? – Saty

回答

1

好吧,我刪除$這個 - >負載>庫(」電子郵件');從模型,因爲它被稱爲舊圖書館,它工作順利,感謝所有的幫助,您的意見幫了我很多

相關問題