我正在开发一个Codeigniter项目,并从phpmailer添加了最新版本,并使用本教程创建了一个mailer_model
https://phpsblog.wordpress.com/2010/02/14/phpmailer-en-codeigniter/
在我改编之后,我在另一个模型上使用它并且工作得很完美。
现在在这个问题上我有这个恼人的错误
这是我的自定义库
<?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;
}
}
?>
我希望你能帮助我解决这个问题
更新
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;
}
}
}
?>
更新01-09-2015
现在我更新了phpmailer类,并为PHPMailerAutoload.php更改了所需的类(请参阅上面的更新代码)
关于这个问题的模型是有效的,但另一个不是,并且给了我这个错误
这是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;
}
答案 0 :(得分:1)
好的,我删除了$ this-&gt; load-&gt; library('email');来自模型,因为它叫一个旧的图书馆,它运作顺利,感谢所有的帮助,你的评论帮助了我很多