无法实例化邮件函数 - Codeigniter 和 PHPMailer



我想使用 PHPMailer 发送电子邮件,我正在使用 Codeigniter

public function check_email(){
$response = array('error' => false);
$email = $this->input->post('email');
$check_email = $this->fp_m->check_email($email);
if($check_email){
$this->load->library('phpmailer_library');
$mail = $this->phpmailer_library->load();
$mail->setFrom('from@example.com', 'Mailer');                
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = "Reset Password";
$mail->Body = "
Hi,<br><br>
In order to reset your password, please click on the link below:<br>
<a href='
http://example.com/resetPassword.php?email=$email
'>http://example.com/resetPassword.php?email=$email</a><br><br>
Kind Regards,<br>
Kokushime
";
if($mail->send()){
$response['error'] = false;
$response['message'] = "The Email Sent. Please Chect Your Inbox";
}else{
$response['error'] = true;
$response['message'] = "There's Something wrong while sending the message". $mail->ErrorInfo;
;
}
}else{
$response['error'] = true;
$response['message'] = 'The email that you entered is not associated with admin account';
}
echo json_encode($response);
}

但它给了我错误无法实例化邮件功能。 顺便说一句,我没有使用SMTP,因为我不需要它。 希望你能帮我:)

你没有包括你的PHPMailer配置。 由于您没有使用SMTP,因此您有此设置吗?

$mail->isSendmail();

此外,假设您使用的是 CI3,如果您使用 composer 安装 PHPMailer 并使其自动加载,可能会更容易。

我刚刚对此进行了测试,它使用 sendmail 工作正常。

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
class Phpmailer_test extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
//Server settings
$mail->isSendmail();                                
//Recipients
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addReplyTo('info@example.com', 'Information');
//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
}

相关内容

  • 没有找到相关文章

最新更新