问题
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
<?php
...
require __DIR__ . '/vendor/PHPMailer/PHPMailerAutoload.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:
Parse error: syntax error, unexpected end of file in C:\wamp\www\commway\vendor\PHPMailer\class.phpmailer.php on line 2995
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.
回答1:
I have this code running :
// 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
with structure :
PHPMailer-Master
-class.phpmailer.php
-class.pop3.php
-class.smtp.php
-PHPmailerAutoload.php
来源:https://stackoverflow.com/questions/37338535/cant-get-phpmailer-working