joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

Email send fails when using phpmail/sendmail on some servers

Open ron4mac opened this issue 1 year ago • 1 comments

Steps to reproduce the issue

Set Joomla instance to use PHP Mail or Sendmail. Perform some activity that causes email to be sent (registration, contact).

Expected result

Generated email is sent without issue

Actual result

Error: Could not instantiate mail function.

System information (as much as possible)

Joomla 4 or 5 on Siteground hosting

Additional comments

Some systems fail when attempting to send email which has the recipient name and email set to the same value (501 error).

libraries/src/Mail/MailTemplate.php

* @since   4.0.0
*/
 public function addRecipient($mail, $name = null, $type = 'to')
 {
     $recipient          = new \stdClass();
     $recipient->mail    = $mail;
     $recipient->name    = $name ?? $mail;    <<<<==== 
     $recipient->type    = $type;
     $this->recipients[] = $recipient;
}

addRecipient() is often called with only an email address, which causes the name to be set to the same as email. This is causing failure on some servers (or their mail servers).

Possible workaround

$recipient->name = $name ?? strstr($mail,'@',true);

Additional preferable solution

All Joomla calls to this addRecipient() method provide an appropriate name argument.

ron4mac avatar May 18 '24 01:05 ron4mac

It is kind of server protection from users who trying to send spam. I think Joomla should not try to set a name if it not provided, it is totally fine to have only an email.

Fedik avatar May 18 '24 07:05 Fedik

I have this problem, I'm following the discussion.

morphinestyle avatar Feb 12 '25 15:02 morphinestyle

BUMP

ron4mac avatar Feb 12 '25 16:02 ron4mac

It is kind of server protection from users who trying to send spam. I think Joomla should not try to set a name if it not provided, it is totally fine to have only an email.

No, I have always used dedicated servers or at most VPS. Unfortunately, I'm not sure whether the issue is caused by the new Joomla versions or the new servers...

I see that Joomla is unable to use phpmail or sendmail. I don't know how long this issue has existed because I remember it working in the past, and I haven't noticed exactly when it stopped functioning.

On my server, I can get phpmail to work, but only with the "-f" parameter on the sender. Honestly, I'm not sure whether the problem is with the server or Joomla, but I am certain that there are no restrictions on port 25 or email sending from my host.

morphinestyle avatar Feb 12 '25 17:02 morphinestyle