Phpmailer: where is vendor/autoload.php?

Created on 4 Sep 2017  路  26Comments  路  Source: PHPMailer/PHPMailer

I keep seeing references to a 'PHPMailerAutoload.php' and '.../vendor/autoload.php'. Are they supposed to be included with PHPMailer? I don't see either here. If it isn't, where do I get it? Am I misunderstanding something?

Most helpful comment

Thanks for getting back with me each time, BTW. I can't believe how patient, professional, and awesome your answers are.

All 26 comments

vendor/autoload.php is something generated by composer, and is a very popular and standardised way of installing packages that you might want to use in a web app. It essentially replaces what the old PHPMailerAutoload.php script used to do in older versions of PHPMailer, but works for all packages, not just PHPMailer.

The basic idea is that you tell composer you want to use one or more packages, it goes and gets them, and builds an autoload script that means their classes are ready to use as soon as you want them. It generally eliminates all other uses of include/require in your app.

For PHPMailer classes, you can avoid having to use composer by loading the class files from src/ directly (this is mentioned in the readme), but as soon as your app grows beyond trivial examples it will rapidly get out of hand, unmaintainable, and slow; composer is the way to go, and nearly all common PHP packages use it.

Totally sorry for submitting this issue (I came here just now to delete it before somebody wasted their time on it). I should have Googled first and asked questions later. I've just tried countless configs with PHPMailer over the last few days and can't get it to work. I'm in a vicious circle of errors that just keep repeating when I try different solutions. When I fix one, something else seems to break. I've gotten beyond the common errors everyone seems to ask about and I'm in my own little land of frustration. Thanks for the awesome explanation though--it's actually better than the actual Composer documentation.

Okay, I figured out how to use Composer and installed PHPMailer using that instead of doing it manually. My server doesn't like the "use" command I see in all your examples. Is there a prerequisite I'm unaware of to use "use"? I'm going to change it back to "require" until I find an answer and see if that works.

Yes, you need to be using a version of PHP that supports namespaces, which means PHP 5.3 or later. Given that PHP 5.2 has been out of support for over 6 years, I'd recommend upgrading to 5.6 at the very least, and you need to be running at least 5.5 to run PHPMailer 6.0 anyway. See here for current PHP support windows.

You don't have to use use, it's just a way of making code a little clearer to work with; it imports namespaced classes into the current namespace, meaning you don't have to use fully-qualified class names everywhere, e.g.

use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer;
$isvalid = PHPMailer::validateAddress($email);

Equivalent code without use:

$mail = new PHPMailer\PHPMailer\PHPMailer;
$isvalid = PHPMailer\PHPMailer\PHPMailer::validateAddress($email);

use is also unrelated to require; use is for aliasing classes; require is for loading PHP files.

I got use to work after moving it outside the class. I'm using PHP 7. When I use port 587, the error "SMTP ERROR: Failed to connect to server: Connection refused (111)" is thrown on line 1639. When I use port 25, error "STARTTLS command failed" is thrown on line 1785. Telnet doesn't like 587 but likes 25 (I just read somewhere there's a bug with PHPMailer that makes me use 25 but since my 587 doesn't seem to be working, I don't think it's related). I can send and receive email locally and remotely. I have ports 25 and 587 open. I have spent days, honestly, trying everything I find. OpenSSL is enabled. I have a shiny, brand new cert from LetsEncrypt. All other https-related stuff is working. My hostname passes tests I throw at it. I'm going to chase after this 587 thing not working thing.

Thanks for getting back with me each time, BTW. I can't believe how patient, professional, and awesome your answers are.

Oh, and also BTW, I've always been happy and carefree with previous versions of PHPMailer. I just switched from shared to VPS and I'm experiencing quite the learning curve. I'm certainly not blaming your software.

I don't know where you're connecting to, but it may be that your host blocks outbound SMTP to port 587, and redirects port 25 to their own servers. That would explain both the symptoms you're seeing. Diagnosing things like this is covered in the troubleshooting guide. I'd check your cert with the openssl s_client command mentioned in there.

I don't know of any port number related bugs in PHPMailer - it's usually problems with the network & hosting, as PHPMailer doesn't care what ports you use. Got a reference?

Reference? Um ... yeah ... I think, as it turns out, it might be, "Turn the page in my fat CentOS 7 Linux Server manual and config Postfix to use my TLS before bothering the PHPMailer people and wasting 2-3 days" but I could be wrong. I'll let you know.

Completed that task. For whatever it's worth, telnet now likes 587. Still doesn't work. I've been combing through the troubleshooting guide. Hadn't tried s_client yet and the response included "verify error:num=18:self signed certificate" ... the TLS + Postfix tutorial tasks I'd just completed from my book included generating a self-signed certificate and I wondered if that would work. I have one from LetsEncrypt. Would that work better? How is LetsEncrypt with PHPmailer? In your opinion, is paying for one better?

By default PHP itself will reject self-signed certs - the guide shows how to allow PHPMailer to accept them, though it's better not to do that. Letsencrypt certs are fine for email servers, no need to pay for one. If you set SMTPDebug = 3 it will show connection and TLS errors.

Coolness. I'll hunt down where that cert is and update my configs. Thanks again for all your feedback and help. I can't remember if I set that debug ... I set some debug to 2. I'll do this, too.

I know this isn't a PHPMailer thing but any guidance would be appreciated. I tried to update/renew using certbot, adding "mailtime.roxorsoxor.com" (hostname/subdomain for my mail server) but certbot told me there wasn't a vhost for that. Where can I add it? I'm not sure what I should do to add it as a virtual host without changing my main hostname. The whole domain, DNS, etc. thing confuses the crap out of me. Do I add "VirtualHost mailtime.roxorsoxor.com:587"? I can't do "*:80" with ServerName of "mailtime ..." can I? What confuses me is there's no separate DocumentRoot because it's just the mail server. Or do I even need to do any of that? Do I just point to the current cert like I said in the previous comment?

Validation of letsencrypt can be tricky for non-web things, but yes, you can just create a new host with that ServerName and give it its own root folder somewhere harmless - it only has to work during validation, but there's no particular harm in having it respond on port 80 - that won't interfere with you mail server. Probably easiest to set it up using webroot mode.

It is my mail server -- I'm worried about it interfering with the "regular" website.

Don't worry - you can add vhosts without interfering with your existing site. The only time it might be an issue is if you already have a web service running under your mail server's host name, for example for webmail - I do that on my own domains.

Cool. I'll try today to find and config like I said a few comments back. I'm writing a bunch of tutorials that I hope are more thorough and clear for folks like myself. Right now, they're just a jumble of notes as I do things by trial and error. Learning a lot and having fun.

I think I'm making progress because now I get:

2017-09-06 19:55:43 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed:
2017-09-06 19:55:43 SMTP ERROR: User & Password command failed: 535 5.7.8 Error: authentication failed:
SMTP Error: Could not authenticate.

Error thrown from PHPMailer line 1798. I don't know to what user & pw it refers.

Presumably that which is set via Username and Password properties. I can't tell without seeing your code or the rest of the SMTP transcript.

I've spent another few hours trying everything I find on Google ... here's the full ...

2017-09-06 23:19:14 SERVER -> CLIENT: 220 mailtime.roxorsoxor.com ESMTP Postfix
2017-09-06 23:19:14 CLIENT -> SERVER: EHLO www.roxorsoxor.com
2017-09-06 23:19:14 SERVER -> CLIENT: 250-mailtime.roxorsoxor.com250-PIPELINING250-SIZE 10485760250-VRFY250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2017-09-06 23:19:14 CLIENT -> SERVER: STARTTLS
2017-09-06 23:19:14 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-09-06 23:19:14 CLIENT -> SERVER: EHLO www.roxorsoxor.com
2017-09-06 23:19:14 SERVER -> CLIENT: 250-mailtime.roxorsoxor.com250-PIPELINING250-SIZE 10485760250-VRFY250-ETRN250-AUTH PLAIN250-AUTH=PLAIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2017-09-06 23:19:14 CLIENT -> SERVER: AUTH PLAIN
2017-09-06 23:19:14 SERVER -> CLIENT: 334 
2017-09-06 23:19:14 CLIENT -> SERVER: xxx=
2017-09-06 23:19:18 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: 
2017-09-06 23:19:18 SMTP ERROR: User & Password command failed: 535 5.7.8 Error: authentication failed: 
SMTP Error: Could not authenticate.
2017-09-06 23:19:18 CLIENT -> SERVER: QUIT
2017-09-06 23:19:18 SERVER -> CLIENT: 221 2.0.0 Bye
SMTP Error: Could not authenticate.
Crap! 
Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not authenticate. in /var/www/html/stakeout/vendor/phpmailer/phpmailer/src/PHPMailer.php:1798 Stack trace: #0 /var/www/html/stakeout/vendor/phpmailer/phpmailer/src/PHPMailer.php(1638): PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array) #1 /var/www/html/stakeout/vendor/phpmailer/phpmailer/src/PHPMailer.php(1409): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Wed, 6 Se...', 'This is a multi...') #2 /var/www/html/stakeout/vendor/phpmailer/phpmailer/src/PHPMailer.php(1256): PHPMailer\PHPMailer\PHPMailer->postSend() #3 /var/www/html/stakeout/class.gator.php(114): PHPMailer\PHPMailer\PHPMailer->send() #4 /var/www/html/stakeout/insert_gator.php(48): USER->send_mail('[email protected]', 'Welcome to Stak...', 'Confirm Registr...') #5 {main} thrown in /var/www/html/stakeout/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 1798

I see it says "auth plain" a couple places. My AuthType = "login" so shouldn't it say login instead of plain?

Please don't paste your password here :-(

The server is only offering PLAIN authentication, so LOGIN won't work - set AuthType = 'PLAIN'. I removed your encoded id and password from that transcript.

Wouldn't have recognized the encoded id & pw. If it was totally in plain text, I feel really stupid. Will test this change later. I live in Tampa so we've been rather busy.

I changed it to "plain" and got exactly the same result. You don't need to respond--I'm going to look for a different solution. I've wasted too much time on this. I need to get real work done so I'm just going to remove the email component for right now. Thanks for all your help, though.

It's case-sensitive.

That didn't change anything but thank you.

Was this page helpful?
0 / 5 - 0 ratings