E-mail activation not working with php mail

The <br> tag is used in HTML to create new lines. In plain text files, this is done with the \n or \r\n special characters (depending on operating system used).

Pro tip: you can use the nl2br PHP function to convert the \n characters in a string to <br> tags.

\n and <br /> are the same tag, but <br /> is used only to do a line break in HTML browsers, \n is used as a new line on other programming languages.

Hello!

I have the following error when using phpmailer:

Fatal error : require(): Failed opening required ‘/home/pianocou/public_html/includes…/PHPMailer/PHPMailerAutoload.php’ (include_path=‘.:/opt/cpanel/ea-php73/root/usr/share/pear’) in /home/pianocou/public_html/includes/signup2.php on line 460

This is the code I use to open the file:

require DIR.‘…/PHPMailer/PHPMailerAutoload.php’;

I think it should be correct because signup2.php is in the includes folder and I have to go back a folder to access phpmailer folder

I now have the following error: How do you use this instead of autoload?

Deprecated : __autoload() is deprecated, use spl_autoload_register() instead in /home/pianocou/public_html/PHPMailer/PHPMailerAutoload.php on line 45
Mailer Error: SMTP connect() failed. Troubleshooting ¡ PHPMailer/PHPMailer Wiki ¡ GitHub

Also, when using the following code to display errors, must it be on every single page?

ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘On’); //On or Off

You can use the latest version of PHPMailer (the master branch) while you are on PHP 7.3.

Which version is that and where do I get the latest version? Also, must I put the error reporting on every page that I want to debug? So I don’t have to use the spl_autoload? I thought that the file you gave me is the latest version?

So must I include the following on every single page? I read somewhere that I have to if I were to use the following code:

ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘On’); //On or Off

I found phpmailer version 6 but not sure how to use it…should I just replace the following files?

Must I put the error reporting on every page? I read somewhere that you must include the code on every page but am not sure

I am getting the following error when trying to use phpmailer version 6

I am getting a class PHPMailer.php not found but I am sure that the following command is correct:

include_once __DIR__.'/../PHPMailer/Exception.php';
include_once __DIR__.'/../PHPMailer/PHPMailer.php';
include_once __DIR__.'/../PHPMailer/SMTP.php';

I think the …/ means to go back a directory?

I am not sure if I have to check something in my php.ini file?

You must upload the files inside the src folder of it on your PHPMailer folder, but delete the files of the older version!

Yes, you must put error reporting on every page.

include_once includes the files just once, require requires them. The ../ means to go back a directory. You even need to use these classes (include these lines just at the start of the mailer file):

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

Are you on a different cPanel than ours (seen from the url https://cpanel.space:2083)? You can even require PHPMailer without __DIR__ variable, but just with this (replace your lines with these):

require "../PHPMailer/Exception.php";
require "../PHPMailer/PHPMailer.php";
require "../PHPMailer/SMTP.php";

Then define the $mail function as new PHPMailer(true), and try to connect to SMTP, send an email and throw a success if it’s successful. If not throw an exception, defined by the PHPMailer Exception.php file, that throws a Mailer Error.

Thanks but my cpanel does not recognise the function use? I am using cpanel.space at the moment and just trying out their cpanel there… but so my following lines should work?

include_once DIR.‘/…/PHPMailer/Exception.php’;
include_once DIR.‘/…/PHPMailer/PHPMailer.php’;
include_once DIR.‘/…/PHPMailer/SMTP.php’;

No, they won’t work at all. See what I said before:

But for some reason, it doesn’t recognise the use function… says unexception or something… Says syntax error… unexpected t-use

Then the variable use isn’t supported on your cPanel, but InfinityFree, Byethost and their affiliates do. Even on my AWS server the “use” variable is working fine without “Syntax error: unexpected “T_USE”, expected {something else} in {filelocation} on line x”.

I am using php version 7.3 I think, so it should be working there?

I don’t know. My mailer script was tested here before PHP 7.0 was replaced with 7.3 and with my AWS Ubuntu server with Apache 2.4.29, PHP 7.2 and the latest version of MariaDB and phpMyAdmin. Maybe it would work for you if the PHP version of cpanel.space has enabled use variables.

I have a feeling that the main problem is with using a full path… is there another way to write it?

require "/home/{your cPanel username}/public_html/PHPMailer/{PHPMailerfiles}.php";

is the full way to write it.

I tried this code and it seems to be progressing but now I have a smtp failed to connect:

$mail = new PHPMailer\PHPMailer\PHPMailer;

You need to call the class PHPMailer with this method:

$mail = new PHPMailer(true);