Skip Navigation

[Resolved] Test email from post form fails with server error 500

This thread is resolved. Here is a description of the problem and solution.

Problem: I'm using the WP Mail SMTP plugin to send SMTP emails. When I use the Forms Test Email feature, I receive an AJAX error 500 with the error log text as follows:

PHP Fatal error: Cannot declare class PHPMailer\PHPMailer\SMTP, because the name is already in use in /path/to/site/wp-includes/PHPMailer/SMTP.php on line 30

Solution: In this case, another SMTP plugin provided an error-free solution. It appears to be a problem in the WP Mail SMTP plugin itself, as other errors are reported for the same plugin on third-party support forums.

Relevant Documentation:
https://wordpress.org/support/topic/php-fatal-error-cannot-declare-class-phpmailerphpmailersmtp/

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 14 replies, has 3 voices.

Last updated by chrisH-34 3 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1761747

I have been working with WPForms on this but they insist the issue is not on their side.

I am using the plugin WP SMTP to allow WordPress to send SMTP email. This changes the wp_mail() function to use SMTP mail.

This work fine in all other areas on my WordPress site. However, in toolset when I setup an email from a post form and send a test email I get:

AJAX Request failed!

Response Code: 500

Response Message:

There has been a critical error on your website.

#1761839

Can you turn on server logs so I can get more information about the error? If you're not familiar with server logs I can show you how to activate one temporarily: Go in your wp-config.php file and look for

define('WP_DEBUG', false);

Change it to:

define('WP_DEBUG', true);

Then add these lines, just after the WP_DEBUG line:

define('WP_DEBUG_LOG', dirname(__FILE__) . '/error_log.txt');
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
define('WP_DISABLE_FATAL_ERROR_HANDLER',true);

Run the test once again. If any server-side errors are triggered during this process, it will create an error_log.txt file in your site's root directory. Use FTP to look for this file in the same directory as wp-config.php. You may need to click "Refresh" in your FTP browser to see a new file appear. Please download this file to your computer, open it in any text editing software, and send me its contents. Once that is done, you can revert the changes you made to wp-config.php and delete the log file using FTP.

#1761865

This is the error message.

[30-Aug-2020 20:17:21 UTC] PHP Fatal error: Cannot declare class PHPMailer\PHPMailer\SMTP, because the name is already in use in /home/dragonslist/public_html/wp-includes/PHPMailer/SMTP.php on line 30

#1762439

Okay thank you. Can you confirm that this issue occurs when only Toolset plugins and the SMTP plugin are active with a default theme, like Twenty Twenty, active? This will help us rule out a conflict with some other third-party plugin like WP Forms.

#1762447

I have tested removing all other plugins but not changing the theme.

I will disable all plugins, change the theme, and test now

#1762473

I have verified he issue still occurs with the default theme and only the plugins Toolset Types, Toolset Forms, and WP Mail SMTP

#1762649

OK thank you for the additional information. I'd like to run a test on my local environment to see if I can replicate the error you mentioned. Can you tell me more about your WP Mail SMTP setup so I can replicate your configurations?
- Go to WP Mail SMTP > Settings
- What is the From Email?
- Is "Force from email" checked?
- What is the From Name?
- Is "Force from name" checked?
- Which mailer system is selected?
- How are you sending a test email - from the WP Mail SMTP Email Test feature, or from the Toolset Forms Send Test Email feature?

I have activated private reply fields here for security. You can add fake information if necessary to submit your reply.

#1763469

Thanks, can you tell me who your SMTP provider is? I'm not sure how to go about testing this without an SMTP account set up, so I'm asking my team for some additional advice.

#1763475

Also I'm seeing a similar error reported here for the WP Mail SMTP plugin:
https://wordpress.org/support/topic/php-fatal-error-cannot-declare-class-phpmailerphpmailersmtp/
Maybe it's an issue in the SMTP plugin itself. Is it possible to try a different SMTP plugin?

#1763525

I will try another plugin and see. Thank you for that.

Also, I use AWS SES from Amazon for SMTP

#1763529

Thanks, I'll stand by for your update.

#1763557

Using a different SMTP plugin solved the issue.

I should have known that toolset was written better than wpforms.

My interaction with their support team led me to believe the issue was with toolset however it was not.

Thank you for such great support and such a great product.

#1771355

Which other SMTP plugin solved this issue?

#1776295

Hi @larryl, unfortunately I'm not aware which plugin he implemented to replace the WP Mail SMTP plugin. Ticket authors do not always see updates about comments in resolved tickets. @chrish-34, if you read this message, would you mind sharing information about the SMTP plugin you ended up using? If you have a link to the WordPress.org plugin landing page I'm sure other Toolset Users would appreciate knowing which SMTP plugin you found to be acceptable.

Best regards,
Christian C

#1776299

I went with Easy WP SMTP and did not have any issues.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.