PHPMailer require fatal error

Trying to implemenet PHPmailer.

Full code found at https://github.com/RyanReese09/CadeUI/tree/master/system/includes

[30-May-2015 15:08:41 US/Eastern] PHP Warning: require(…/PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 2
[30-May-2015 15:08:41 US/Eastern] PHP Fatal error: require(): Failed opening required ‘…/PHPMailer/PHPMailerAutoload.php’ (include_path=‘.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php’) in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 2

I’m including it as such.

require "../PHPMailer/PHPMailerAutoload.php";

Which, from my Email.class.php file (as seen on GitHub)…that would lead back to the “includes” folder. Then into PHPmailer/PHPMailerAutoload.php

Why is it not found? Could someone help me get this setup?

If you use relative path it should be relative to the script that you actually run in browser (index.php?)
So try:

require 'system/includes/PHPMailer/PHPMailerAutoload.php';
1 Like

I was doing /cadeui/system/includes/PHPMailer/PHPMailerAutoload.php" originally. Same error. I changed it to the …/PHPMailer…etc version just to make it simpler to make sure I wasn’t being stupid.

That /cadeui/ version should work no matter where the original script is running from. I do all my includes like /cadeui/…etc.

Yeah, still error

[30-May-2015 15:26:07 US/Eastern] PHP Warning: require(system/includes/PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 2
[30-May-2015 15:26:07 US/Eastern] PHP Fatal error: require(): Failed opening required ‘system/includes/PHPMailer/PHPMailerAutoload.php’ (include_path=‘.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php’) in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 2

If your app uses single entry point (via index.php) then I wouldn’t mess with relative paths.
Just add this into index.php:

define('PATH', dirname(__FILE__));

and do all of your includes using absolute paths:

require PATH.'/system/includes/PHPMailer/PHPMailerAutoload.php';

this approach is bulletproof and you will not have to calculate relative path in your mind everytime you want to include something

1 Like

Still nope :frowning: .

[30-May-2015 15:34:12 US/Eastern] PHP Warning: require(/home/codefund/public_html/cadeui/system/includes/classes/system/includes/PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 3
[30-May-2015 15:34:12 US/Eastern] PHP Fatal error: require(): Failed opening required ‘/home/codefund/public_html/cadeui/system/includes/classes/system/includes/PHPMailer/PHPMailerAutoload.php’ (include_path=‘.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php’) in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 3

Please view my bootstrap.php file (in my includes folder). I’m using an autoloader there. Could this be, in any way, affecting things?

The file is there on my server. I can see it. Blegh.

No, you’ve added that define in a wrong place.
It should be added in index.php.
And it will only work if any URL of your app is actually runs index.php (app entry point) like they do in most of modern frameworks

1 Like

No. The main idea is require() uses paths relative to the script that you run in browser (and not to the other scripts included in that one). For example, if you use your Email class when user opens blabla.php in browser then path should be relative to blabla.php but not to the Email class itself.

Still nope. But what does this sentence mean?

The actual “app” page will be dashboard.php. This is just a page to allow login and subscribers.

[30-May-2015 15:43:54 US/Eastern] PHP Notice: Use of undefined constant PATH - assumed ‘PATH’ in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 2
[30-May-2015 15:43:54 US/Eastern] PHP Warning: require(PATH/system/includes/PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 2
[30-May-2015 15:43:54 US/Eastern] PHP Fatal error: require(): Failed opening required ‘PATH/system/includes/PHPMailer/PHPMailerAutoload.php’ (include_path=‘.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php’) in /home/codefund/public_html/cadeui/system/includes/classes/Email.class.php on line 2

Modern web apps use “single entry point”. That means no matter what URL you enter in address bar, it will run index.php anyway (hided with rewriting). For example:

_http://example.com/some/path => index.php?uri=some/path
_http://example.com/another/one => index.php?uri=another/one

But I see now you have at least 4 different files for that (index.php, dashboard.php, login.php and logout.php).

So add that define into dashboard.php and try again

I don’t think I explained things clearly. Dashboard.php isn’t coded yet. I don’t think redefining it will help. Index.php is what people are actually viewing right now.

Hmm, how do you test that require()? Which script do you run in browser when you see that error?

[30-May-2015 15:43:54 US/Eastern] PHP Notice: Use of undefined constant PATH - assumed ‘PATH’ in

It will not work if you’re trying to run Email.class.php directly. I assume you include this class somewhere else (in the main app) and not run it via URL

1 Like

I go to index.php

Then I am filling out the newsletter section at the bottom.

This then goes to process-home.php (in the includes folder). This process-home.php called Subscriber.class.php (in the class folder) which (the class) then calls Email.class.php. The Email.class.php is the one with the PHPMailer require.

Ok, that means process-home.php is the file you actually run in browser when your require() is fired.
And if you want to use relative path you ought to calculate it from process-home.php.
Try this:

require "PHPMailer/PHPMailerAutoload.php";

or, if you want to use absolute path instead, add this to process-home.php:

 define('PATH', dirname(__FILE__));

and change require to:

require PATH.'/PHPMailer/PHPMailerAutoload.php';
1 Like

Ok now there is no error, but the script is appearing to timeout? Then I get some server error page. It says 404 but I don’t know whether I believe that…

Then I CTRL+R (resubmit form data) and it says double entry. So that means the PHP script actually ran and inserted the e-mail into my database. It’s probably stalling out on the Email.class.php PHPMailer code. Is any of that wrong?

That code seems ok. Try to comment it out to prove the problem is there.

1 Like

Yup. The problem is the PHP mailer. I’m going to slowly uncomment. Standby.

Ok it only fails when I get to the actual sending.

I’m following these instructions - http://www.sitepoint.com/sending-emails-php-phpmailer/

Where am I going wrong?

try to remove that line

$mail->isSMTP(); 

to see if the problem is in SMTP connection

1 Like