-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading PHPMailer 6.0 #959
Comments
This is just namespacing. Look at the examples for reference - you need to either
or
|
Just to confirm, I altered the beginning of the gmail example to look like this (i.e. to not use composer), and it worked fine: use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '../src/PHPMailer.php';
require '../src/SMTP.php';
require '../src/Exception.php';
//Create a new PHPMailer instance
$mail = new PHPMailer; |
No work I copied your lines to make certain of no typo errors, require MAILER_DIR .'/src/PHPMailer.php'; This is in my functions file |
I replied this via GitHub
No work I copied your lines to make certain of no typo errors,
These are in my config file, which is called before the functions file
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require MAILER_DIR .'/src/PHPMailer.php';
require MAILER_DIR .'/src/SMTP.php';
require MAILER_DIR .'/src/Exception.php';
No errors on these requires
This is in my functions file
$mail = new PHPMailer; I even took out the (test)
same error
*Fatal error*: Uncaught Error: Class 'PHPMailer' not found in .....
using PHP Ver: 7.1.0;
…On 1/11/2017 2:26 PM, Marcus Bointon wrote:
Just to confirm, I altered the beginning of the gmail example to look like this, and it worked fine:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '../src/PHPMailer.php';
require '../src/SMTP.php';
require '../src/Exception.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#959 (comment)>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX5f65maSL7ZBJ61tHhNzg84o1U_d13Xks5rRSzUgaJpZM4Lg7Sd>.
|
Ah, well that's a PHP issue.
If you move the |
Many thanks. That worked Just so I'm clear. Does version 6 require the use of namespace? If so, would be good to make this point explicit in the upgrade [Upgrading from PHPMailer 5.2 to 6.0] and examples files. |
Yes - The classes are namespaced, so any references you make to them must respect that, just like anything that uses a namespace. It's is covered pretty thoroughly in the upgrade guide, which is linked from the readme, though the link doesn't work because it's expecting it to be in master, which it's not, yet. It's already reflected in all the example files in the 6.0 branch, though obviously not in the 5.2/master branch. |
I saw the "You *will need to* import classes you're using explicitly into your own namespace, or the global namespace -
all the examples show how to do this."
In my opinion, this is not very explicit. Suggest rewording to read *"*You *Must *import classes you're using
explicitly into your own namespace, or the global namespace.
I believe this feature will cause a lot of grief to others as they attempt to upgrade the phpMailer 5.xx installations
to 6.xx. Once I got the classes to load the 6.0, my 5.2.21 smtp mode settings ran perfect without any changes.
Seems to me the use of namespace should be an option, not a requirement.
Al....
…On 1/11/2017 5:55 PM, Marcus Bointon wrote:
Yes - The classes are namespaced, so any references you make to them must respect that, just like anything that uses a
namespace. It's is covered pretty thoroughly in the upgrade guide
<https://github.com/PHPMailer/PHPMailer/blob/6.0/UPGRADING.md>, which is linked from the readme, though the link
doesn't work because it's expecting it to be in master, which it's not, yet. It's already reflected in all the example
files in the 6.0 branch, though obviously not in the 5.2/master branch.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#959 (comment)>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX5f68UuWiyk4BBFZJxEUOhNhqEQUpJDks5rRV3KgaJpZM4Lg7Sd>.
|
Unfortunately you can't have it both ways - it's all or nothing. Namespacing is pretty important for libraries - there have been quite a few issues caused by class name clashes with SMTP in particular, it's simply expected of any modern library, and it's probably the single most requested feature. This issue isn't specific to PHPMailer, it's exactly the same with all namespaced libraries & frameworks, which now covers Symfony, Zend, Laravel, Drupal, and pretty much everything else now. In your case you were doing something that would break any namespaced library, not just PHPMailer. All this kind of messing about with loading classes and defining things in the right place manually is precisely why composer exists; if you're using composer, you can pretty much forget about ever needing to know where a class file is. Anyway, I can make the wording a little stronger to make it unambiguous. |
Hello, I used the composer for install phpmailer, on my project, but when i call de autoload i receive the error Uncaught Error: Class 'PHPMailer' not found in C:\wamp64\www\php\tpl\email.php:24 Stack trace: #0 {main} thrown in C:\wamp64\www\php\tpl\email.php on line 24. What do i can do ? Thanks for help! |
I can't tell from what you posted. Do what it says in the readme, base your code on the examples provided. |
Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer' not found used this $mail = new PHPMailer(true); almost tried everythin help...... |
Read this thread, do what it says in the readme, base your code on the examples provided. |
Hi synchro, I have the same problem.And I am navigating to this page using ajax.I installed it manually unziped the file and just added to my folder. require ('PHPMailer/src/PHPMailer.php'); $mail = new \PHPMailer(true); |
Do what it says in this thread. You have exactly the same problem and should use the same solution. |
I tried everypart.
Am I doing it right? |
Yes, except that you have asked PHPMailer to throw exceptions (by passing |
When I tried exception error catch i git the error like 'syntax error, unexpected 'use' (T_USE)',I am not sure what to do? |
Just like the examples say: <?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'include/PHPMailer/src/Exception.php';
require 'include/PHPMailer/src/PHPMailer.php';
$mail = new PHPMailer(true);
try {
//The rest of your mail sending code goes here
} catch (Exception $e) {
echo 'Error: ', $e->getMessage();
} If your code fails on the first |
ok.I checked and found it to be the latest version.that is PHP Version 7.1.29.This is the latest version. |
Current PHP is 7.3.6, but 7.1.x is new enough to have support for |
OK.Thanks for your response.Iwill recheck it |
Hi Synchro, Hi everybody. I'm a new member. Mojave OS X. MAMP php7.3.1. Google emails. I created a folder named "email" inside htdocs. Inside this folder, I created email.php (directly from your simple example) and I placed manually the folder "PHPMailer-master" and "vendor". I've just created a new google account for my trials : "[email protected]" with his password "pwdAccount2". To send an email-test to my previous email "[email protected]". The result : the mail is told sent. Was severely blocked by google, with about 20 lines of error from PHP mailer. Here is my code : <?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
require 'PHPMailer-master/src/Exception.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
try {
//Server settings
$mail->SMTPDebug = 2; // 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 = '[email protected]'; // SMTP username
$mail->Password = 'pwdAccount2'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('account1.com', 'Joe User'); // Add a recipient
// $mail->addAddress('[email protected]'); // Name is optional
// $mail->addReplyTo('[email protected]', 'Information');
// $mail->addCC('[email protected]');
// $mail->addBCC('[email protected]');
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?> |
Welcome to Github. Please don't post comments on old, closed issues, especially when they are not related to your problem - it sends notifications to everyone that has ever been part of the thread. It sounds like your script is working fine, but you have debug output enabled, so turn it off by setting |
Sorry, 'didnt' see the "closed" mention at the top. I'll try your new setting, thank you |
Thank dear Marcus Bointon. I'll take care next about the closed topics.
At the moment setting SMTPDebut to 0 just makes the errors disappearing but
did not cancel the severe google mail blocking nor probably the error from
PHP Mailer (just masked). No email received. Nor sent.
I tried unsuccessfully you gmail example furnished. May be my MAMP-inside
working ? Outside composer. Outside user/local/... So I have to work hard
first and seek deeper about my bugs before posting again.
Hery
Le mar. 23 juil. 2019 à 18:03, Marcus Bointon <[email protected]> a
écrit :
… Welcome to Github. Please don't post comments on old, closed issues,
especially when they are not related to your problem - it sends
notifications to everyone that has ever been part of the thread.
It sounds like your script is working fine, but you have debug output
enabled, so turn it off by setting SMTPDebug = 0.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#959?email_source=notifications&email_token=AMVZL6MVA4FF4D2NLSM33YTQA4TWLA5CNFSM4C4DWSO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2TTOLQ#issuecomment-514275118>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMVZL6NGLRQ4K3X6F6CHBOLQA4TWLANCNFSM4C4DWSOQ>
.
|
You said the email was sent? In that case set |
Really annoying when they go bump in the night, did you rtfm? Stop hijacking closed topics. |
Having problem with upgrading phpMailer 5.xx to 6.0. Used several versions of phpmailer for years, no problems like this. I prefer to not use composer.
From upgrade guide "Alternatively, if you're not using composer, copy the contents of the PHPMailer folder into one of the include_path directories specified in your PHP configuration and load each one manually." I prefer to not modify the include_path file on a shared host.
I used the PHPMailerAutoload.php for my 5.xx versions
I used this from the 6.0 package: "Upgrading from PHPMailer 5.2 to 6.0 If you're not using composer, you can still load the classes manually, depending on what you're using:" ```
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/PHPMailer.php';
require 'src/SMTP.php';
// No errors reported on these
$mail = new PHPMailer(true);
Fatal error: Uncaught Error: Class 'PHPMailer' not found in ///path to my code
Tried $mail = new \PHPMailer(true);
Tried lower case file names for PHPMailer.php and SMTP.php
Tried class.PHPMailer.php and class.SMTP.php; and with lowercase filenames
The text was updated successfully, but these errors were encountered: