Skip to content
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

Error with swiftmailer #2068

Closed
dessemon opened this issue Mar 9, 2022 · 5 comments
Closed

Error with swiftmailer #2068

dessemon opened this issue Mar 9, 2022 · 5 comments
Assignees
Labels
Projects
Milestone

Comments

@dessemon
Copy link

dessemon commented Mar 9, 2022

Describe the bug
When you create a new article in the administration, in debug mod, you have these errors :
Uncaught exception: 'Error'

Message: 'Call to undefined method Swift_Mailer::newInstance()'

Stack trace:

/var/www/html/phpmyfaq_prod/src/phpMyFAQ/Mail.php(561): phpMyFAQ\Mail\SwiftSMTP->setAuthConfig()
/var/www/html/phpmyfaq_prod/src/phpMyFAQ/Notification.php(89): phpMyFAQ\Mail->send()
/var/www/html/phpmyfaq_prod/admin/record.add.php(215): phpMyFAQ\Notification->sendNewFaqAdded()
/var/www/html/phpmyfaq_prod/admin/index.php(361): require('/var/www/html/p...')
{main}
Thrown in '/var/www/html/phpmyfaq_prod/src/phpMyFAQ/Mail/SwiftSMTP.php' on line 51

To Reproduce
Steps to reproduce the behavior:

  1. In administration, go to 'content' and 'Add new faq'
  2. Click on 'Save'
  3. See error

Screenshots
image

phpMyFAQ (please complete the following information):

  • phpMyFAQ version : 3.1.1
  • PHP version PHP/7.4.28
  • Database 5.5.5-10.5.15-MariaDB
  • Elasticsearch no

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser : Chrome
  • Version : 98
@dessemon
Copy link
Author

dessemon commented Mar 9, 2022

A track : swiftmailer/swiftmailer#925

@thorsten thorsten self-assigned this Mar 10, 2022
@thorsten thorsten added the Bug label Mar 10, 2022
@thorsten thorsten added this to To do in 3.1.2 via automation Mar 10, 2022
@thorsten thorsten added this to the 3.1.2 milestone Mar 10, 2022
3.1.2 automation moved this from To do to Done Mar 10, 2022
@yann2-0
Copy link

yann2-0 commented Mar 16, 2022

Hello,

I had the same problem in the log
'Call to undefined method Swift_Mailer::newInstance()'

I solved the problem in the following way:

  • edit in /src/phpMyFaq/Mail/SwiftSMTP.php
  1. In the setAuthConfig function replace

    $this->mailer = Swift_Mailer::newInstance(
    Swift_SmtpTransport::newInstance($server, $port, $security)
    ->setUsername($this->user = $user)
    ->setPassword($pass)
    );

by:

$transport = new  Swift_SmtpTransport($server, $port, $security);
$transport->setUsername($this->user = $user);
$transport->setPassword($pass);
$this->mailer = new Swift_Mailer($transport);
  1. In the send function replace

$message = newSwift_Message::newInstance($headers['Subject'])->setFrom( [empty($sender) ? $this->user : $sender] )->setTo($recipients)->setBody($body);

by:

$message = new Swift_Message($headers['Subject']);
$message->setFrom([empty($sender) ? $this->user : $sender]);
$message->setTo($recipients)->setBody($body);

For me that solved the problem.

Thorsen was there another way to solve the problem?

Thanks for this app.

Cordially.

@thorsten
Copy link
Owner

@yann2-0 see the referenced commit above, this is the correct way. phpMyFAQ 3.1.2 will be released soon to address this issue.

@yann2-0
Copy link

yann2-0 commented Mar 16, 2022

@thorsten ok sorry i'm new to git

@thorsten
Copy link
Owner

@yann2-0 no worries! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
3.1.2
Done
Development

No branches or pull requests

3 participants