XF 2.3 Contact Form: SMTP 554 5.7.1 Error due to From/Envelope-From mismatch (Namecheap Private Email)

Can

Member
Hi there,

I'm using XenForo 2.3.7 on two forums with contact forms enabled:

https://fenerbahceforum.com
https://almancakulubu.com

My mail service is through Namecheap's Private Email (SMTP), which strictly requires the "From" and "envelope-from" headers to match the authenticated domain email address. Otherwise, it rejects the message with the following error:

554 5.7.1 <From> and <envelope-from> fields in the email headers don't match. Reason: JFE040011

In my XenForo admin panel, I have correctly set the "From" address to match the authenticated SMTP user (iletisim@fenerbahceforum.com, etc.).

However, XenForo’s contact form currently uses the visitor’s email as the "From" address, which causes Namecheap to reject the emails — even though the SMTP authentication and headers are otherwise valid.

Namecheap support confirmed that using the visitor’s email in the "Reply-To" field is the correct and allowed way. So I would like to configure XenForo’s contact form to send mail as:

– From: iletisim@fenerbahceforum.com (authenticated domain address)
– Reply-To: [visitor's email]

Is there a built-in way to achieve this in XF 2.3.7?
If not, is there a recommended way to override this behavior (e.g., via Misc.php or by writing a small add-on)?

Any guidance, code snippet, or recommended approach would be greatly appreciated.
Thank you in advance!

– Can
 
Is there a built-in way to achieve this in XF 2.3.7?
If the option above posted by @Pauly does not help, deactivate it and try the following.

I just looked at the MiscController class in src/XF/Pub/Controller/MiscController.php:

PHP:
    protected function setupContactService()
    {
        $contactService = $this->service(ContactService::class);
        $visitor = \XF::visitor();
        $input = $this->filter([
            'username' => 'str',
            'email' => 'str',
            'subject' => 'str',
            'message' => 'str',
        ]);
        if ($visitor->user_id)
        {
            $contactService->setFromUser($visitor);
            if (!$visitor->email)
            {
                if (!$contactService->setEmail($input['email'], $error))
                {
                    throw $this->exception($this->error($error));
                }
            }
        }
        else
        {
            $contactService->setFromGuest($input['username'], $input['email']);
        }
        $contactService
            ->setMessageDetails($input['subject'], $input['message'])
            ->setFromIp($this->request->getIp());
        return $contactService;
    }

It calls the ContactService class in src/XF/Service/ContactService.php.

You can try to..

.. find:

PHP:
        $mail->setFrom($mail->getFromAddress(), $this->fromName);

replace with:

PHP:
        $mail->setFrom($options->contactEmailAddress, $this->fromName);



or (if you also want your forum's name as sender name):

PHP:
        $mail->setFrom($options->contactEmailAddress, $options->boardTitle);

Please post back, if this works for you. :)
 
  • Like
Reactions: Can
However, XenForo’s contact form currently uses the visitor’s email as the "From" address, which causes Namecheap to reject the emails — even though the SMTP authentication and headers are otherwise valid.

This is not the default behaviour.

XenForo should be using the value of defaultEmailAddress as the from address and the value of contactEmailAddress as the to address.

The email address specified in the contact form will be set as the reply-to address.

This behaviour is what you described as the ideal setup by Namecheap - so it should work exactly as required.

Do you have any addons installed that change the behaviour of the contact form?

Are you using the Default URL for the contactUrl setting or do you use a custom URL?
 
.. find:

PHP:
        $mail->setFrom($mail->getFromAddress(), $this->fromName);

replace with:

PHP:
        $mail->setFrom($options->contactEmailAddress, $this->fromName);



or (if you also want your forum's name as sender name):

PHP:
        $mail->setFrom($options->contactEmailAddress, $options->boardTitle);

Please post back, if this works for you. :)

Changing core files is almost never the correct solution - this will lead to warnings in the AdminCP about invalid file contents, and any changes will be overwritten by the next upgrade.

This should only ever be used as a last resort to fix a known bug that you know will be addressed in a future release - similar to the way the XF team sometimes releases patches while waiting for the next point release of the software.
 
I could write a small add-on, but first I want to know if my approach is a working solution:

Or you could test the behaviour of XenForo directly and determine that this is not normal behaviour and nothing needs to be fixed in the core - it's something at the OP's end causing this behaviour and any addon is possibly not going to fix it either :rolleyes:
 
Ahh - I had forgotten about the contactEmailSenderHeader setting.

@Can it seems like you have this option checked - look for "Sender info in from header on contact emails" in Email options in Admin CP.

Make sure this option is NOT checked, this should fix your email sending problems.
 
@Sim, you are right, I am not. :notworthy:

My suggested code changes do not change much of XF's behavior (except from changing defaultEmailAddress into contactEmailAddress as the From-address). I see, this does not add much value. :LOL:

It's quite late here, that's the only excuse I have. :sleep:
 
ACP>options>email setup

View attachment 325248

If the option above posted by @Pauly does not help, deactivate it and try the following.

I just looked at the MiscController class in src/XF/Pub/Controller/MiscController.php:

PHP:
    protected function setupContactService()
    {
        $contactService = $this->service(ContactService::class);
        $visitor = \XF::visitor();
        $input = $this->filter([
            'username' => 'str',
            'email' => 'str',
            'subject' => 'str',
            'message' => 'str',
        ]);
        if ($visitor->user_id)
        {
            $contactService->setFromUser($visitor);
            if (!$visitor->email)
            {
                if (!$contactService->setEmail($input['email'], $error))
                {
                    throw $this->exception($this->error($error));
                }
            }
        }
        else
        {
            $contactService->setFromGuest($input['username'], $input['email']);
        }
        $contactService
            ->setMessageDetails($input['subject'], $input['message'])
            ->setFromIp($this->request->getIp());
        return $contactService;
    }

It calls the ContactService class in src/XF/Service/ContactService.php.

You can try to..

.. find:

PHP:
        $mail->setFrom($mail->getFromAddress(), $this->fromName);

replace with:

PHP:
        $mail->setFrom($options->contactEmailAddress, $this->fromName);



or (if you also want your forum's name as sender name):

PHP:
        $mail->setFrom($options->contactEmailAddress, $options->boardTitle);

Please post back, if this works for you. :)

Ahh - I had forgotten about the contactEmailSenderHeader setting.

@Can it seems like you have this option checked - look for "Sender info in from header on contact emails" in Email options in Admin CP.

Make sure this option is NOT checked, this should fix your email sending problems.
Everyone, thank you for your help. I had mistakenly checked the contactEmailSenderHeader setting. After disabling it, the issue was resolved. Thanks again.
 
Back
Top Bottom