2015-09-01 3 views
1

Я работаю над проектом CodeIgniter и добавил последнюю версию с 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 01-09-2015

Теперь я обновил класс 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 -error-out-with-call-to-undefined-method-phpmailersetfrom) – Saty

+0

@Saty спасибо, уже проверил, что пару раз несколько часов назад я использую последние библиотеки, и, как я говорю по этому вопросу, он беспокоится о модель, а по одному из вопросов не –

+2

Вы звоните в библиотеку phpmailer в контроллере ??? – Saty

ответ

1

Хорошо, я удалил $ this-> load-> библиотека (» Эл. адрес'); от модели, потому что она звонила в старую библиотеку, и она работала гладко, спасибо за вашу помощь, ваши комментарии мне очень помогли

Смежные вопросы