How-to · Checked November 22, 2026

How to move a form from a PHP mail script to a form backend

Change the form's action from your PHP file to a form endpoint, keep the field names as they are, test it, then delete the PHP script from the server. The form's HTML barely changes.

People usually make this move because mail sent by PHP's mail function lands in spam or vanishes, because the script is being abused by bots, or because the site is moving to a host that does not run PHP.

Why PHP mail scripts cause trouble

  • Deliverability: mail sent straight from a web server often fails the checks that mail providers run on the sender's domain, so it is filed as spam or dropped without notice.
  • No record: if the email is lost, the message is gone. The script stores nothing.
  • Spam: a script with no filtering forwards everything bots send it.
  • Security: scripts that place form input into email headers without checking it can be abused to send mail to other people.
  • Hosting: static hosts do not run PHP at all.

Steps

  • Create a form at a form backend and copy its endpoint. In FormTango it is on the form's Setup tab.
  • In your HTML, replace the action. Change action="contact.php" to action="https://formtango.com/f/YOUR_FORM_ID" and keep method="POST".
  • Check every field has a name. Rename the visitor's email field to email if it is called something else, so replies go to them.
  • Add the hidden spam trap field.
  • Submit the form on the live site and confirm the submission and the email arrive.
  • Delete the old PHP file from the server.

The changed lines

Before:

<form action="contact.php" method="POST">

After:

<form action="https://formtango.com/f/YOUR_FORM_ID" method="POST">

Plus one new line inside the form:

<input type="text" name="_gotcha" style="display:none" tabindex="-1" autocomplete="off">

Replacing what the script did afterward

The PHP script did thisNow
Sent you an emailThe form backend emails you and stores the submission
Set the visitor as Reply-ToAutomatic on FormTango when the field is named email
Redirected to thanks.htmlA default thank-you page, or your own page with a hidden _redirect field on paid plans
Sent a confirmation to the visitorAutomatic reply, paid plans
Checked required fieldsrequired attributes in the HTML, plus limits on the receiving side
Saved an uploaded fileFile uploads, stored on paid plans

Remove the old script

Do not leave contact.php on the server once the form no longer uses it. Bots that found it earlier keep posting to it directly, so it goes on sending junk mail from your domain. Delete the file and any mail library that came with it.

If you used JavaScript to call the script

Change the address in the fetch or XMLHttpRequest call to the endpoint, send new FormData(form), and add the header Accept: application/json to get a JSON answer. The response shape will differ from your script's, so update the success check: FormTango answers { ok: true, id } or { ok: false, error }. See how to submit a form with fetch.

More help

The HTML form to email guide has a complete form, the form checker confirms your markup, and why your HTML form is not sending email covers the failures people hit along the way. The free plan covers 1,000 submissions a month with unlimited forms. Paid plans start at $9 a month.

Common questions

Do I need to rewrite my form to stop using PHP?
No. Change the action attribute to the form endpoint and keep your fields. The only additions are a hidden spam trap and, if needed, a redirect field.
Why does PHP mail() go to spam?
Mail providers check whether the sending server is authorized for the From domain. A web server's default mail setup often is not, so the message fails those checks.
Can I keep my own thank-you page?
Yes. On FormTango's paid plans a hidden _redirect field sends visitors to your page after a plain form post. On the free plan they see a FormTango thank-you page, or you can send the form with fetch and show your own message.

Written by the FormTango team. Facts about other services were read from their own pages on November 22, 2026. Spotted something out of date? Tell us and we will fix it.

Keep reading