Remove hostname from email with PHP delivery method?

Nurs1927

Well-Known Member
Nov 22, 2015
93
7
58
Spain
cPanel Access Level
Root Administrator
Hello, More information about the problem: Gmail does not validate DKIM and DMARK.
gmail_mail_info.png
I have the correct DNS records and DKIM activated in Cpanel.

This is the Gmail information about the message:
[email protected]: Gmail mail where I send the message
myserver.com: my hostname. I want remove it from Gmail in "via my hostname"
mydomain.com: the domain from which I send the message

NOTE: I send my message from [email protected]

Code:
Delivered-To: [email protected]
Received: by 2002:a67:f743:0:0:0:0:0 with SMTP id w3csp1045030vso;
        Tue, 20 Nov 2018 12:23:26 -0800 (PST)
X-Google-Smtp-Source: AFSGD/UefyeeJjyKpW4p82O5Zy+xJJPBlSlbgyvKxjKmyu0ULeTwuR+6zjt7pUVnXQVOCVix+N06
X-Received: by 2002:adf:8342:: with SMTP id 60mr3155209wrd.212.1542745406108;
        Tue, 20 Nov 2018 12:23:26 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1542745406; cv=none;
        d=google.com; s=arc-20160816;
        b=t8wn7tp0LuvyII+CB613QZPwViWEGfMeI8iwwthYIDESuauRYiNEIN57rzXQz/Yq32
         L/e/IA67GYSuJiSPftTXGGZ8fCwXOfoRwZpPOvPHEtWpetCJM1Nbp8pRihnsNTDefxBQ
         Qy/gQqgwAIYu7z+sfwzwxEXQJSvK0BNYcWs2z/Pjd3tLGZg/jIvPMRktwXF+wMGn6fNi
         cVIZs1PQWnvZsiZoJNx9LXlgv97d+bics7O9ys/Mk8Zbt/w2BFxfyJFPFavGi0iUrmLB
         fHPSI2Q3/sh+vF6G9Gnl5WZzZGnD9NYwuYYluIDwAhkgWD3O54EANcEv/UnirV1cdFNy
         i1Dg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=message-id:content-transfer-encoding:auto-submitted:date:from
         :mime-version:subject:to:dkim-signature;
        bh=TPZa3CrcFIT1OliAB0uPb4LZXk+9QBKRHMhKOTwupjI=;
        b=qrWtdB/bcetPFsJSBwrmJpBSNLA4wSHfEPQjBzRjBETkj4RNJhQFdsVcNcOqfGVH62
         jWOnYpOdU7JlqJeFqSLhN9auD6dMA4eW0+8ZhfQlSMQwrduiM/XPwmKPJExMzYz40LDM
         1LIWdpkEp8xlZjz/v2VV93WQCHuERriWFyBM16e74z0Nfohe8Y2NWtnI4beiIXgX98F2
         +xGe+P8VVOODGBQsMfflJF19YXXsZ7sTB5JJVZabpI0gJhywBxkUvcBLR454X801kbL7
         ZlAxEXyb9wYJRc0M3EdaBJLG35sEQNTEyMdEt+7VsDvV4oOO8JqExbAGYhZegoDWXtq/
         90SQ==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=fail [email protected] header.s=default header.b=M125UGTn;
       spf=pass (google.com: best guess record for domain of [email protected] designates MY SERVER IP as permitted sender) [email protected];
       dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mydomain.com
Return-Path: <[email protected]>
Received: from myserver.com (myserver.com. [MY SERVER IP])
        by mx.google.com with ESMTPS id f7si17159416wri.400.2018.11.20.12.23.25
        for <[email protected]>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 20 Nov 2018 12:23:26 -0800 (PST)
Received-SPF: pass (google.com: best guess record for domain of [email protected] designates MY SERVER IP as permitted sender) client-ip=MY SERVER IP;
Authentication-Results: mx.google.com;
       dkim=fail [email protected] header.s=default header.b=M125UGTn;
       spf=pass (google.com: best guess record for domain of [email protected] designates MY SERVER IP as permitted sender) [email protected];
       dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mydomain.com
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mydomain.com; s=default; h=Message-Id:Content-Transfer-Encoding: Content-Type:Date:From:MIME-Version:Subject:To:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=TPZa3CrcFIT1OliAB0uPb4LZXk+9QBKRHMhKOTwupjI=; b=M125UGTnSWIdmMCfCGl+p8805y iroY9G2MLrP754ViY+AEdK2B1d7BrPS+dZO7aM8OT4+Z36WlXJ/fpopHu0rlKEhTIayo2Knq5gDmN r2ZXh9o6AKO48au5yTKS5mJx076cR6uvM/itGMWY+cGKZ2HICX9/wVl59IIYJwmajAUAfX/dCt8MP HeNsyDW71TVt3YHW+Bckikb8WEsVYKQQQFl8DPfO1aUMMPuxnAhpgAbitTeyRZMSuSheSimf3vxxi v5qgYRuovunJ4CpHg+WIwu3ma9QXmklxznHTJdy4ibL/JYNOCq/z02I5hIhE4pdMAEzsbP/G7VpwO BsVeFRlA==;
Received: from myuser by myserver.com with local (Exim 4.91) (envelope-from <[email protected]>) id 1gPCYP-0001sf-1P for [email protected]; Tue, 20 Nov 2018 21:23:25 +0100
To: [email protected]
Subject: Test Email
X-PHP-Script: www.mydomain.com/forum/admin/index.php for 213.77.159.243, 213.77.159.243
X-PHP-Originating-Script: 1002:Php.php
MIME-Version: 1.0
From: “MY WEBSITE“ <[email protected]>
Date: Tue, 20 Nov 2018 20:23:25 +0000
Auto-Submitted: auto-generated
Content-Type: multipart/alternative; boundary="--==_mimepart_ac94a8ef280c2d028e877b00d75fb4ae"; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-Id: <[email protected]>
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - myserver.com
X-AntiAbuse: Original Domain - gmail.com
X-AntiAbuse: Originator/Caller UID/GID - [1002 992] / [47 12]
X-AntiAbuse: Sender Address Domain - myserver.com
X-Get-Message-Sender-Via: myserver.com: authenticated_id: myuser/from_h
X-Authenticated-Sender: myserver.com: [email protected]
X-Source:
X-Source-Args: php-fpm: pool mydomain_com
X-Source-Dir: mydomain.com:/public_html/forum/admin
 

Nurs1927

Well-Known Member
Nov 22, 2015
93
7
58
Spain
cPanel Access Level
Root Administrator
email_in_out.png

information from forum developers: We set "From" as your outgoing address, and "Reply-To" as the user's address (or your incoming address, depending upon the context)
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
465
113
UK
cPanel Access Level
Root Administrator
I agree 100% with @Infopro, there is really no good reason in this day and age not to use an authenticated SMTP connection to a valid email address to send mail from a PHP script, especially since your forum system already supports it as shown on your post #4

I would guess that your issue arises because the envelope from: address defaults to the server name. You could try editing the mail() line in the PHP code and add the fifth parameter. eg '-f [email protected]' (obviously, replace the address with a valid address that should exist as a real address in your cPanel mail accounts.)

There is no guarantee that this will work consistently, but it may help.

See PHP: mail - Manual for full details
 
Last edited:
  • Like
Reactions: cPanelLauren

Nurs1927

Well-Known Member
Nov 22, 2015
93
7
58
Spain
cPanel Access Level
Root Administrator
That's not a valid reason to not use SMTP, IMHO. ;)

Why not configure your forum to use SMTP email with a valid email address and give it a try?
Right! I congigured with SMPT, but DKIM fails.

This is the information about:
- I have an external SMTP mail service that works perfectly in webmail an in mail manager. DKIM Pass
- But in my forum, with SMTP de DKIM fail.

Code:
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
    d=domain.com; s=default; h=Content-Transfer-Encoding:Content-Type:Date:
    Subject:From:To:MIME-Version:Sender:Reply-To:Message-ID:Cc:Content-ID:
    Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
    :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:
    List-Subscribe:List-Post:List-Owner:List-Archive;
    bh=IrJOEAdWflUD5xQWM3DnVREQ4Q2XfJ6qIhwLznIcQwI=; b=G+43HyS0qwPaOCdJC/gUUhvoyX
    p6v+Rgi5YMrG4drXu3d4jgots4PJmY2kGsQ1j2Wn5dliQTY3d/TqvUTfkAyBDxd03VzZ95qwXdX9J
    GCs9qkDniVDc/CU4AZ3dYIUFw0aMxus8EhECbVL+ectUI+Z8WSJ07IKqKLaS+wJmI0vp5/UbOfATg
    z69X9G9CLketNcbbjnMAecMSS6qrI/kvM1f7WeWZrQSK0a81pLKnHHA8KjoyucTG6MpT2F08JaFMp
    fNlr3fdvgBwUm6Gn7nIq8bCYB2pw0DaATfIFHLcvXv9G7OM1nic1dfTwn/oX8//uDdyTWHAEAv86x
    Wr6Wybuw==;
Signed-by: [email protected]
Expected-Body-Hash: IrJOEAdWflUD5xQWM3DnVREQ4Q2XfJ6qIhwLznIcQwI=
Public-Key: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtnyYHWHAjyHuHnl1iLJ9AGJvtN3D2BJ6lKZqPBYl+3hQc/+X+awH4a9tFAGyQH0Gp5xFYCkLA7kg1b77RNdvkMMdyyGiF7loWGL5ZA/mwMyf4J2HJxlA5O5M2kCuTZ/3KqvaEhcI2VZbfchLgaHlTCkd6dFUWmBSqLuEIOq6FhxFgbaf8XoiDDSthKjasu75viggzzkbeZRXPkanftPeDKs7TMpGL9v5BcWCd5pmYRN3NjulivAsoZGfotu3MgLcsiVqmbKT8xKav5qZ1cRsR7YUFhYh5dzarKHzeaDloc8SkY3R0FIl9prw29R12gVhxWovrr5H73CGARjpIE87iQIDAQAB;

DKIM-Result: fail (bad signature)
This is the forum developer answer:

Hello, Im not sure on what your hosting company is referring to here, but DKIM is controlled by the server, not the application. We simply send a mail through SMTP to the SMTP account.
My mail company tested and all works perfectly.

Can the problem may be in some cpanel configuration in my server?
 

Nurs1927

Well-Known Member
Nov 22, 2015
93
7
58
Spain
cPanel Access Level
Root Administrator
We're probably going to need some additional details about this comment, then.
You're right.
I have contracted a hosting mail service (external to my dedicated server). I use it via Cpanel webmail , and I also have it configured in my Mail Manager with the SMTP data: host, port, SSL, user, pass.
Everything works correctly, and messages are validated through DKIM.

The problem is when I use the mail service through my server, configuring the SMTP data in my forum system.
It is here when validating DKIM does not work.

1.- On my server, I have the DKIM key configured in CPanel, and also in the DNS of my server provider.

2. - Mail hosting company, checked everything and it works without problems.

3.- Forum developer, say that "...DKIM is controlled by the server, not the application. We simply send a mail through SMTP to the SMTP account."

4.- I have my website with cloudflare, but I have DKIM in the cloudflare DNS and also, with cloudflare off, the problem continues.

5. - In my server company DNS interface I can´t paste the same DKIM key as in Cpanel, so they say say that:
"TXT strings over 255 characters must be divided into several strings and indicated without line breaks. Please copy this record into your zonefile:(DKIM key provided for them)"

6.- - Mail hosting company say that: "If we make a query of the DKIM registry of your domain, we can see that it returns the following:(MY DKIM key)
if we check the DKIM record assigned to your domain in CPanel, we see the one we provide in this line:(My DKIM key with quotation in middle)
If you analyze it in detail you will see that there is a quotation in the middle of the line, which breaks the DKIM record. Fix this, please"


¡But I can´t find de DKIM key with quotation in any site!
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,296
1,271
313
Houston
6.- - Mail hosting company say that: "If we make a query of the DKIM registry of your domain, we can see that it returns the following:(MY DKIM key)
if we check the DKIM record assigned to your domain in CPanel, we see the one we provide in this line:(My DKIM key with quotation in middle)
If you analyze it in detail you will see that there is a quotation in the middle of the line, which breaks the DKIM record. Fix this, please"
Where is DNS for your domain hosted? On your server or at the registrar? It sounds like DNS is hosted at the registrar/remote and the DKIM you're updating isn't being reflected. If it is pointed to your server you might try the following:

1. Check the DNS zone file for an additional record

2. Go to cPanel>>Mail>>Authentication - > disable then re-enable the DKIM
 
  • Like
Reactions: Nurs1927

Nurs1927

Well-Known Member
Nov 22, 2015
93
7
58
Spain
cPanel Access Level
Root Administrator
Hello, I have my DNS in:
1.- Cloudflare
2.- My server provider:hetzner.de
3.- In my domain registrar I have de Cloudflare Nameservers.
4.- In My CPanel server I have de DKIM generated by Cpanel (I deactivated it and reactivated)

1. Check the DNS zone file for an additional record
Sorry, what do you mean?
 
Last edited by a moderator:

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,296
1,271
313
Houston
Hello, I have my DNS in:
1.- Cloudflare
2.- My server provider:hetzner.de
3.- In my domain registrar I have de Cloudflare Nameservers.
4.- In My CPanel server I have de DKIM generated by Cpanel (I deactivated it and reactivated)
I didn't realize you'd stayed with CloudFlare - they have special instructions for adding DKIM and they have instructions on doing so which can be found here: How do I add DKIM records?

Thanks!
 

QAZwsxED

Member
Oct 4, 2020
9
0
1
Australia
cPanel Access Level
Website Owner
I recently solved a similar issue.
Solution: manually add a Message-Id (note not a Message-ID) header then connect and send an email.
cPanel WHM adds a Message-ID header and re-arranges the 'h' record in the DKIM signature which invalidates it, causing a DKIM:fail in the recipients mailbox.