PHP Form reply address
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x


I use a .php form that has two responses after sending, one is an automatic reply that goes to the sender, and the second sent the order to the domain owner (admin@domain). When a sender writes into form, the automatic response has the header from: admin@domain and that is fine. The problem occurs when the domain owner get the mail where he is in the header from himself and can not reply because he is automatically responding to himself (he should manually enter the mail from the sender and that is definitely not the solution).

Script has to 3 method: mail, sendmail and SMTP. First two methods works fine and owner got order with sender's name and mail address, but I strongly have to move on SMTP because first two methods has some issue or hosting ISP has. Now I need to programming SMTP. Owner account mail address is on GSuite.

Action and config files has the main SMTP data, but I share all php files:

Form on web:

Hi Saaskoo, there seems to be a logical error,
are you planning to send an email to the owner on behalf of another gmail user without his/her authorization like you do for domain gmail id? Ps: Smtp config has your email id & pwd in the function, so every time it gets called, mail will get shot using your email id as the sender.
SilverHood Apps 21 days ago
I understand what you say, it looks like I want to send the form as a sender. And it works smoothly when I type in a SMTP user that is create classically in cPanel, but not if it's a GSuite account.
Saaskoo 21 days ago
Hmm... Looking at line 1195 of file class.phpmailer.php, $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; it says if & only if there is no sender then use the From field.. Else there is sender then use the sender's email address.
Might this logic be related as though why its taking name properly but not email? As sender value is never equal to '' ?
SilverHood Apps 21 days ago
Maybe, but @Wuddrum was pretty well diagnosis, Google or GSuite simply does not allow it to be sent anything other than its own SMTP email.
Saaskoo 21 days ago
awarded to Wuddrum

Crowdsource coding tasks.

2 Solutions

Winning solution

Looks like gmail is rewriting the From field if you don't own that address. More info

Your best bet is to find another SMTP provider that doesn't restrict you to only using email addresses that you own.

Hey Wuddrum, it's not a concrete solution, but hey, you helped me figure out how to turn around and look for other options. Actually, you helped me so much that I did not tap in the place. Thank you very much!
Saaskoo 18 days ago
Thank you for awarding the bounty!
Wuddrum 18 days ago


...i might have an idea why it didn't work, i have faced a similar problem before within an old project when moving from cPanel mail to Gsuite Mail.

if the script was working properly when using your cPanel SMTP mail, but stopped working after changing to GSuite Mail, then this 99% could be the solution. Otherwise, i'm addressing something different. So you could ignore my solution.

cPanels are configured to use only a single mail provider, when changing to Gsuite Mail:

  • you are completely canceling your old cPanel mail provider: in other words, you couldn't have admin@domain from Gsuite and no-reply@domain (assuming no-reply who's sending auto emails) from cPanel working together. they both have to be from the same provider! (both from Gsuite, or Both from cPanel).
  • keep in mind that they are by default sent to spam folder since they are sent from different dns address (GSuite address is different than the original website dns address). to solve that, there is some configs you have to deal with to bypass the spam folder.
  • your Gsuite account, could send emails on behalf of your website (admin@domain could send emails from your Gsuite account since emails are sent from your Gsuite SMTP servers), but they couldn't receive emails unless you connect your GSuite account to your domain following the last configs i spoke about.
  • once completed, you could send and receive emails as wanted on behalf of your website as Gsuite users on bealf of your website.

I'm speaking from an old experience, if you think that the bug is within your code, you could ignore my solution. But i highly recommend you look for cPanel configs. they are minor sensitive details, that we should take care of when changing to GSuite accounts.

**Note: My experience was with a Namecheap Hosting Domain.

(but i believe they all have the same criteria considering mail providers, at least that what support team said.)

If what i said mean something for you, you could contact me and we could check the server cPanel configs together.

Hey Chlegou, many thanks for your comprehensive answer. I think I know what you're talking about and this is config of my DNS in cPanel: v=spf1 +a +mx +ip4:*...* ~all There is Google, my Hosting provider and some free SMTP providers (Wuddrum suggestion) SPF settings. Now I can get mail order from .php for my ISP and some Free SMTP providers, but not at all from Google. For all the others I get the header that is sent from their server and the field is adapted to be written by the sender. Only Google GSuite does not allow and always writes from myself. Am I addressing something wrong write it freely.
Saaskoo 19 days ago
yes, I'm talking about spf configs, but keep in mind there is additional configs you have take care of also! ( I forgot details, but I still remember there is some additional configs...) considering source code, I didn't check it yet, since first thoughts was about configs. From Gmail (same as gGuite) you could send email to your own email address, so I believe it should work... but maybe we need to verify it who knows.... could you give a temporary access to your email? If yes, I will check it tonight. Otherwise, you could use the no-reply@domain approach sending a copy for owner and another one to the admin whith reply to is adressed to sender and admin (both of them) ... as I said, if you could provide access, I will check it tonight.
Chlegou 19 days ago
Thanks for that Chlegou, but now it works with SMTP settings of my ISP, and some free SMTP providers such as Sendgrid (thanks @Wuddrum). Now, I only have to keep track of whether the form will be sent regularly when the site visitor fills and sends it or something goes wrong.
Saaskoo 19 days ago
In this case, you better move on to cms, saving form data to database, ans sending emails from there.... more professional.....
Chlegou 19 days ago
Thanks, I hope the time will come for it :)
Saaskoo 19 days ago
Hey Chlegou, thank you for all the advice and for the time you invested in the answers. Tips for coffee :)
Saaskoo 18 days ago
Thanks for the tip! :)
Chlegou 18 days ago
View Timeline