0

..\www\solicitudes\index.php

..\www\solicitudes\conexion.php

..\www\solicitudes\PHPMailer\all the files descompressed from the downloaded zip https://github.com/PHPMailer/PHPMailer

I am having troubles instantiating the PHPMailer class, in conexion.php file I write the following line:

require_once('PHPMailer/PHPMailerAutoload.php');

and this error is showed

Fatal error: Class 'PHPMailer' not found in C:\AppServ\www\SolicitudesBE\conexion.php on line 58

I have changed the locatation of the file without success

                 require_once('PHPMailer/PHPMailerAutoload.php');
                //require_once('PHPMailer/class.phpmailer.php');        

                $mail = new PHPMailer;                  

                $mail->IsSMTP();
                //$mail->SMTPDebug = 2; 
                $mail->SMTPAuth = false; 
                $mail->SMTPSecure = "tls";  
                $mail->Host = "correo.domain.org.mx";   
                $mail->Port = 25;
                $mail->Username = "julio.castor@domain.mx";
                $mail->Password = "pass";
                $mail->SetFrom('correo@domain.com', 'Julio Castor');
                $mail->Subject = $asunto;   

Has any body can help me with this issue? By the way, this project works fine in others computers as server (local) but when I upload to the server (Windows server 2003) the error is showed.

I cannot get access to the server yet but as I can, where could I look for to configure the server?

July
  • 442
  • 4
  • 11
  • It must be the path issue in your server . Check it . – Drudge Rajen Feb 26 '16 at 18:22
  • do you mean \\IP\www\SolicitudesBE\PHPMailer or C:\AppServ\www\SolicitudesBE\PHPMailer? I have tried both... No one of them works – July Feb 26 '16 at 18:33
  • first find the abosulte path to your file, and then use it . – Drudge Rajen Feb 26 '16 at 18:41
  • C:\AppServ\www\SolicitudesBE\PHPMailer\PHPMailerAutoload.php this is the path that I write in require_once but dont make any change, the same error, and the files downloaded are in the same path – July Feb 26 '16 at 18:49
  • Set a breakpoint in the autoloader and you'll see why it's not finding the files. Why are you not using composer? – Synchro Feb 27 '16 at 07:06
  • the problem is that the server doesnt find the class mailer, I have tried this http://stackoverflow.com/questions/28906487/fatal-error-class-phpmailer-not-found but in the server show an error regarding not composer file found... So I think that the settings server is the issue, something like permissions of accessing. Do you know how to re configure the server about class or php initial settings? – July Feb 28 '16 at 01:00
  • as of now (Feb 2018), autoloader is gone from PHPMailer: https://stackoverflow.com/a/49121147/1246870 – avs099 Apr 10 '18 at 16:08

4 Answers4

1

try to include

use PHPMailer\PHPMailer\PHPMailer;
0

Try

require_once(__DIR__ . '/PHPMailer/PHPMailerAutoload.php');

where DIR is the path of the current file.

olibiaz
  • 2,551
  • 4
  • 29
  • 31
  • I think your problem is not in the require of the autoload but in the autoload itself. Try to print out what PhpMailerAutoload.php generate. Which php version have you on the server? Maybe check the permissions folders – olibiaz Feb 26 '16 at 19:13
  • the php version in the server is 6.0, In the folder where the file is located has permissions of read only. also the same project that i did in the localhost has lower php version. I will try to figure out about phpmailerautoload.php – July Feb 26 '16 at 19:43
  • php version 6 doesn't exists. you mean 5.6? – olibiaz Feb 26 '16 at 19:46
  • the php version I use in the local is PHP: 5.6.15 and the one use in the server is 6.0.0-dev I took these with phpversion(); – July Feb 26 '16 at 19:54
  • ok, php v6 have been aborded, you should not used it. Anyway, you should try to print out the PHPMailerAutoload.php, try to dump the $filename at line 29 and see which classes are loaded. – olibiaz Feb 26 '16 at 19:55
  • Do not use PHP 6, it's long abandoned and years out of date. – Synchro Feb 27 '16 at 07:05
  • I tried modifying the class to know where is the issue, the line require_once doesnt have problems, the error is in the line $mail = new PHPMailer; I refered the classes individually (class.phpmailer.php and class.smtp.php) but a new error is showed about missing SSL. I have no idea what the problem is. do you thing that it is regarding server settings? – July Feb 28 '16 at 01:07
  • Yes, your error is from the new PHPMailer, cause the autoload seems to not load the class/file properly. Did you debug the PHPMailerAutoload.php to see which classes are loaded? – olibiaz Feb 29 '16 at 20:36
0

The issue is resolved, I changed the server (Appserver) with XAMPP (version for windows server 2003) the error was not about the code, it was the server (maybe could be the composer dependecies). Anyway, it is working! Thanks for your assistancce

July
  • 442
  • 4
  • 11
-1

Try using,

require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PHPMailer' . DIRECTORY_SEPARATOR . 'PHPMailerAutoload.php');

if not works try,

require_once('PHPMailer/class.phpmailer.php');
require_once('PHPMailer/class.phpmaileroauth.php');
require_once('PHPMailer/class.phpmaileroauthgoogle.php');
require_once('PHPMailer/class.pop3.php');
require_once('PHPMailer/class.smtp.php');

I hope this will work.

Masum Nishat
  • 167
  • 3
  • 15
  • I did this to know if there are differences in the path: $dir= dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PHPMailer' . DIRECTORY_SEPARATOR . 'PHPMailerAutoload.php'; || echo "
    " . $dir ; || echo "
    " . __DIR__ . '\PHPMailer\PHPMailerAutoload.php'; but is the same path that is showed C:\AppServ\www\SolicitudesBE\PHPMailer\PHPMailerAutoload.php C:\AppServ\www\SolicitudesBE\PHPMailer\PHPMailerAutoload.php
    – July Feb 26 '16 at 18:53
  • are you sure that orginal file are in this location? – Masum Nishat Feb 26 '16 at 19:17