Can't get PHPMailer working [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

This question already has an answer here:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!