First of all - im newby in github. I just found an error and fixed it on my site, but i hope that i can help to community)))
Joomla! 3.6.4
JFactory::getMailer() generate an error while registering new user in administrator interface or when user tries to register itself
User registred succesfull
Get "Fatal error: Call to a member function addRecipient() on a non-object in /home/host1526565/gagarinskaya-usadba.ru/htdocs/www/plugins/user/joomla/joomla.php on line 141"
from administrator interface.
Error message while self registering.
This solution works for me.
First of all the problem in this section:
In "plugins/user/joomla/joomla.php" line 134:
$mail = JFactory::getMailer()
->setSender(
array(
$this->app->get('mailfrom'),
$this->app->get('fromname')
)
)
->addRecipient($user['email'])
->setSubject($emailSubject)
->setBody($emailBody);
This code generate an error " Call to a member function addRecipient() on a non-object "
I simply rewrite code:
$mail = JFactory::getMailer();
$mail->setSender(
array(
$this->app->get('mailfrom'),
$this->app->get('fromname')
)
);
$mail->addRecipient($user['email']);
$mail->setSubject($emailSubject);
$mail->setBody($emailBody);
That works fine.
Next, same error, but whitout "fatal error screen":
In "components\com_users\models\registration.php" lines 159, 197, 558, 598:
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
Code returning false and don`t send emails.
But in my case works this:
$mailer = JFactory::getMailer();
$mailer->setSender(
array(
$data['mailfrom'],
$data['fromname']
)
);
$mailer->addRecipient($row->email);
$mailer->setSubject($emailSubject);
$mailer->setBody($emailBody);
$return = $mailer->Send();
Dump of joomla sys-info in JSON
systeminfo-json.zip
Labels |
Added:
?
|
I checked my settings, and you right - it fix the problem.
Thanks)
But, maybe it still important thing?
I think, its not good to trow fatal error, when I just forget to set site-email, doesn`t it?
That's why I said the code fix is correct
Even better would be to check for an error like at https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/mail/mail.php#L738-L741 and do something knowing that setting up the email to be sent has failed (the message might still send but depending on which method fails it would be missing data).
Yes, you right, its better)))
In fact, I thought, that my version of php doesn``t support this way of creating objects, thats why i wrote an issue. )))) I```m not a php-developer)))
I am guessing, will be useful to add warning message, that say something like "email cannot be send because you don`t set site email", or something like this.
Which is why the fix is NOT correct. It doesn't handle error situations correctly!
The construction of the mail should be enclosed in a try / catch. Failing to construct should result in same message as failing to send. You may choose for a separate message but the handling is expected to be the same. Again, IGNORING it is not the right thing to do!
Hi. @sovainfo - I agree with you. In my situation, I just doesn``t knew the reason of error. And I thought, that problem in generating an mailer object.
I realized, that my solution is wrong.
Nevertheless, I don`t delete this issue, because this problem should be handled.
Category | ⇒ | Libraries |
Status | New | ⇒ | Confirmed |
Build | master | ⇒ | 3.6.4 |
Status | Confirmed | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-05-29 22:02:39 |
Closed_By | ⇒ | brianteeman |
The code fix is technically correct, any of the methods adding email addresses can return a boolean false value. However, this also indicates a configuration issue on your site. The
setSender()
method is rejecting the email address configured as the from address, you'll want to check your site's configuration to make sure you've got a valid address there.