问题描述
我正在努力设置PHPMailer并在我的应用程序中工作.
I am struggling to get PHPMailer setup and working in my application.
安装似乎很简单.我的目录结构如下:
The installation seems simple enough.My directory structure looks like this:
|-[controllers]
|---controller.php
|-[vendor]
|---[PHPMailer]
|------class.phpmailer.php
|------PHPMailerAutoload.php
|-index.php
index.php
index.php
<?php
...
require __DIR__ . '/vendor/PHPMailer/PHPMailerAutoload.php';
...
?>
controller.php
controller.php
<?php
include('vendor/PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
...
?>
这与示例所获得的一样简单,但是当我运行它时,出现以下错误:
That's pretty much as simple as the example gets, but when I run this, I get the following error:
一切正常,我看不出我是如何做到这一点的.我什至尝试将所有内容都移到index.php
文件中,但得到的结果相同.我一呼叫$mail = new PHPMailer();
,就会引发错误.
Everything was working fine, I can't see how I've managed to break this.I have even tried moving everything to just the index.php
file but I get the same result. As soon as I call $mail = new PHPMailer();
it throws the error.
推荐答案
我正在运行以下代码:
// PHPmailer
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SMTP; // Specify main and backup SMTP servers/*
$mail->From = EMAIL;
$mail->FromName = SENDER;
$mail->addAddress($Email, $FirstName); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $mailSubject;
$mail->Body = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent to ' . $Email . "<br>";
}
// end of PHPmailer
具有结构:
PHPMailer-Master
-class.phpmailer.php
-class.pop3.php
-class.smtp.php
-PHPmailerAutoload.php
这篇关于无法使PHPMailer工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!