[英]Strange Fatal error: Call to undefined method PHPMailer::SetFrom() With Codeigniter
I am working on a Codeigniter project and added last version from phpmailer, and used this tutorial to create a mailer_model 我正在研究Codeigniter项目,并从phpmailer添加了最新版本,并使用本教程创建了mailer_model
https://phpsblog.wordpress.com/2010/02/14/phpmailer-en-codeigniter/ https://phpsblog.wordpress.com/2010/02/14/phpmailer-en-codeigniter/
After I adapted, I used it on another model and works perfect. 改编后,我在另一个模型上使用了它,并且效果很好。
Now on this one I have this annoying error 现在在这个我有这个烦人的错误
Here is my custom library 这是我的自定义库
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class My_PHPMailer {
public function My_PHPMailer()
{
require_once('PHPMailer/PHPMailerAutoload.php');
}
}
?>
Here is the model with the issues 这是有问题的模型
<?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;
}
}
?>
I hope you can help me to solve this issue 希望您能帮我解决这个问题
UPDATE UPDATE
Mailer_Model.php 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 = "mygmail@gmail.com"; // la cuenta de correo GMail
$mail->Password = "mypasshere"; // password de la cuenta GMail
$mail->SetFrom('laboratory@test.com', 'Crossover Laboratory'); //Quien envía el correo
$mail->AddReplyTo('laboratory@test.com', '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 更新2015年1月9日
Now I updated the phpmailer class, and changed the required class (see updated code above) for PHPMailerAutoload.php 现在,我更新了phpmailer类,并更改了PHPMailerAutoload.php所需的类(请参见上面的更新代码)
The model on this question is working, but in the other one is not, and gives me this error 关于这个问题的模型正在工作,但是在另一个问题上却没有,并且给了我这个错误
And this is the function with the issues inside Patients_model 这是Patient_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;
}
Ok, I removed $this->load->library('email'); 好的,我删除了$ this-> load-> library('email'); from the model because it was calling an old library, and it worked smoothly, thanks all for your help, your comments helped me a lot
从模型中删除,因为它正在调用旧的库,并且运行顺利,感谢大家的帮助,您的评论对我有很大帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.