I’m new to PHP and trying to set up an SMTP mail thing, following https://github.com/PHPMailer/PHPMailer/ but keep getting an error called “Class ‘PHPMailer’ not found”.
I’m guessing it is quite a simple fix - I think I have followed the instructions, I have been reading about similar errors for a couple of hours now and nothing fixes it. Oh I should add that it is on my Contact Me page on http://ineedaweatherforecast.co.uk/.
So at the top of my index file I have require (‘phpmailer/PHPMailerAutoload.php’);
My form later in index.php references - this has the following code (and more):
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'my e-mail'; // SMTP username
$mail->Password = 'my password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
phpmailer is the directory where all the required files such as class.phpmailer are stored.
Thanks for your response. I don’t know what namespaces are so I assume I am not using them. I did try with your amendment but still got the same error.
As far as I can see, every file is in the right location.
The original error code is Fatal error: Class ‘PHPMailer’ not found in /var/sites/i/ineedaweatherforecast.co.uk/public_html/phpmailer/formmail.php on line 3
Do you think it could be something to do with the “var/sites/i/” bit? I have no idea why it is putting that in?
Did you install using composer? If so then require ‘vendor/autoload.php’; Composer is really the way to go.
If not, try adding error_reporting(E_ALL); at the top of your file. Might get an error message. Verify phpmailer/PHPMailerAutoload.php actually exists.
PHPMailer is a fine component but if you just getting started you might want to use a more up to date package such as SwiftMailer. Nowadays, just about everything uses composer and namespaces.
I had require (‘phpmailer/PHPMailerAutoload.php’); - is that not sufficient? I did also try include rather than require That was right at the top of my page.