Form does not submit in MOST browsers

#1

Hello, and thank you for creating a forum which will help people like me solve problems. I have tried so many help sites and have tried so many options but am a loss. I have looked at answers to forum questions but still to no avail.

Basically, I have created a page with a form. I made the page in Dreamweaver so the form already includes ‘required’ fields etc. which seem to work fine (but please let me know if any of my code in the form could be causing an issue/is not compatible).
I wish for the form to be submitted and an email with its contents sent to my email. I have therefore created a php script which is linked to in the form action.

The problem is it does not work in most browsers, and although it sends me to the php action page, it tells me “Sorry, there was a problem sending your message.”.
Saying that, it works in my version of Microsoft Edge on my laptop (but not in another version on my home’s desktop).
I will get the success message and I also receive an email.

I am attaching the code for the form and for the php mail() script if you don’t mind and would very much appreciate it if anyone can see why it isn’t working in most instances.
Please note that although I set up the contactus page with the form on it as an html first, I have since saved it as php but have tried both with the same results so this doesn’t seem to make a difference.

Please also note that I have put generic emails in but I have used real ones in my test pages of course.
So the form is as follows:

<form action="newtestacknowledge.php" method="post" enctype="text/plain" id="ContactForm">
 <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 300; font-size: large;">
  <label for="Name">*Name:</label>
  <input name="Name" type="text" required="required" id="Name" form="ContactForm" size="50" maxlength="80">
  <label for="email"><br>
  <br>
  *Email:</label>
  <input name="Email" type="email" required="required" id="email" form="ContactForm" size="40" maxlength="60">
  <label for="tel"><br>
  <br>
  Phone:</label>
  <input name="Phone" type="tel" id="tel" form="ContactForm" size="30">
  &nbsp;</p>
  <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
  <label for="timezone">Time Zone:</label>
  <select name="timezone" id="timezone" form="ContactForm">
  <option>Eastern</option>
  <option>Central</option>
  <option>Mountain</option>
  <option>Pacific</option>
  <option>Alaska</option>
  <option>Hawaii</option>
  <option>Other</option>
</select></p>

  <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
  <label for="callafter">Best Time to Call:&nbsp;</label>
  <select name="callafter" id="callafter" form="ContactForm">
 <option value="00:00">12.00 AM</option>
 <option value="01:00">01.00 AM</option>
 <option value="02:00">02.00 AM</option>
 <option value="03:00">03.00 AM</option>
 <option value="04:00">04.00 AM</option>
<option value="05:00">05.00 AM</option>
 <option value="06:00">06.00 AM</option>
 <option value="07:00">07.00 AM</option>
 <option value="08:00">08.00 AM</option>
 <option value="09:00" selected="">09.00 AM</option>
 <option value="10:00">10.00 AM</option>
 <option value="11:00">11.00 AM</option>
 <option value="12:00">12.00 PM</option>
 <option value="13:00">01.00 PM</option>
 <option value="14:00">02.00 PM</option>
 <option value="15:00">03.00 PM</option>
 <option value="16:00">04.00 PM</option>
 <option value="17:00">05.00 PM</option>
 <option value="18:00">06.00 PM</option>
 <option value="19:00">07.00 PM</option>
 <option value="20:00">08.00 PM</option>
 <option value="21:00">09.00 PM</option>
 <option value="22:00">10.00 PM</option>
 <option value="23:00">11.00 PM</option>
</select>
  
<label for="callbefore">to</label>
<select name="callbefore" id="callbefore" form="ContactForm">
 <option value="01:00">01.00 AM</option>
 <option value="02:00">02.00 AM</option>
 <option value="03:00">03.00 AM</option>
 <option value="04:00">04.00 AM</option>
 <option value="05:00">05.00 AM</option>
 <option value="06:00">06.00 AM</option>
 <option value="07:00">07.00 AM</option>
 <option value="08:00">08.00 AM</option>
 <option value="09:00">09.00 AM</option>
 <option value="10:00">10.00 AM</option>
 <option value="11:00">11.00 AM</option>
 <option value="12:00">12.00 PM</option>
 <option value="13:00">01.00 PM</option>
 <option value="14:00">02.00 PM</option>
 <option value="15:00">03.00 PM</option>
 <option value="16:00">04.00 PM</option>
 <option value="17:00">05.00 PM</option>
 <option value="18:00">06.00 PM</option>
 <option value="19:00">07.00 PM</option>
 <option value="20:00" selected="">08.00 PM</option>
 <option value="21:00">09.00 PM</option>
 <option value="22:00">10.00 PM</option>
 <option value="23:00">11.00 PM</option>
 <option value="00:00">12:00 AM</option>
 </select>
  </p>
  <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
  <label for="Comments">*Comments/Questions:<br>
  </label>
  <textarea name="Comments" cols="55" rows="6" required="required" id="Comments" form="ContactForm"></textarea>
  <br>
  </p>
  <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: oblique; font-weight: 300; font-size: medium;">*required</p>
  <p>
  <input name="reset" type="reset" id="reset" form="ContactForm" value="reset">
  <input name="submit" type="submit" id="submit" form="ContactForm" formenctype="text/plain" value="submit">
  </p>
 </form>

Here is the php action file in its entirety:

    <?php
if(isset($_POST['submit'])) {

$to = ' "My Name" <me@email.com>';
$visitor_email = $_POST['Email'];
$subject = 'New Submission from SYHTS Contact Form';
$message = 'Name: '. $_POST['Name'] . "\r\n\r\n";
$message .= 'Email: '. $_POST['Email'] . "\r\n\r\n";
$message .= 'Phone: '. $_POST['Phone'] . "\r\n\r\n";
$message .= 'Time Zone: '. $_POST['timezone'] . "\r\n\r\n";
$message .= 'Call After: '. $_POST['callafter'] . "\r\n\r\n";
$message .= 'but Before: '. $_POST['callbefore'] . "\r\n\r\n";
$message .= 'Comments: '. $_POST['Comments'];
$headers = "From: info@domainname.com \r\n";
$headers .="Reply-To: $visitor_email \r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8';
$success = mail($to, $subject, $message, $headers, '-fme@email.com');
}

 function IsInjected($str)
 {
 $injections = array('(\n+)',
   '(\r+)',
   '(\t+)',
   '(%0A+)',
   '(%0D+)',
   '(%08+)',
   '(%09+)'
   );
 $inject = join('|', $injections);
 $inject = "/$inject/i";
 if(preg_match($inject,$str))
 {
 return true;
 }
 else
 {
 return false;
 }
 }

 ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php if (isset($success) && $success) { ?>
<h1>Thank you</h1> Your message has been sent.
<?php } else { ?>
Sorry, there was a problem sending your message.
<?php } ?>

</body>
</html>

I have tried so many different alternatives but each time it either doesn’t make a difference or causes a complete fail such as a 404 error.

I should add that one solution was to add the ‘-fme@email.com’ in the mail() but it makes no difference either way.
I do wonder whether I need another header such as ‘X-Mailer: PHP/’

Thank you for any help that you may be able to offer.

#2

The most likely problem is the above enctype attribute in the form tag. Just remove it.

You can determine what data is being submitted to the form processing code by adding the following line of code on the next line after the opening <?php tag -

print_r($_POST);

You may also have errors in the html of the form page. You should validate your pages at validator.w3.org

#3

Thank you, but none of these work.
I had tried to remove text/plain before and it makes no difference, but have removed for good now anyway.
When I inserted the print_r line, it just goes to a ‘file cannot be found page’.
I inserted it on the line after <php?
and the line before the if(isset line

I had run the validator before.

I am attaching the screenshot of the results. I am not sure how or if to make these changes, but the body error doesn’t make sense to me as there is only one
<body> and one
</body> tag.
I had already changed previous errors such as simple sytax errors etc.

Would it help for me to include the whole contactus.php page file?
could it be something in the css file associated with it?

Thank you.html%20code%20checker%20contactus%20page

#4

The only affect should have been to display an array of the $_POST data. It would take seeing what the url is, that couldn’t be found.

The validator errors probably are not causing the problem, but the body tag belongs after the closing /head tag. You have it after a closing /header tag, which is not the same as the head of the document.

Are you running this on a localhost development system or a live/public server? If on a localhost system, are you sure you are using a URL to the form page, it would start with http://localhost or similar and not directly opening the file the form code is in? If on a live/public server, are you sure the files were successfully upload to the server and you don’t have multiple files at different paths and/or misspelled file names? Also, after making any changes to html in a file, if your browser was open with the previous html in it, you would need to reload the page to get any changes to show up in the browser.

If you put sensitive values from you code into a separate config.php file and require it into your main code, you won’t need to worry about posting your main code.

At this point it would probably take seeing the current version of both files to provide further help.

Finally, unless there’s some javascript on the form page that’s referencing the ids, there’s no point in cluttering up the markup with them and since all the form fields are within the form, using the form=“ContactForm” attribute is more clutter and wasted typing time.

LOL - I just saw the formenctype="…" attribute in the submit button. Remove that as well. This is more needless repetition and clutter.

#5

I will try these things and get back to you.
I am trying it out on a live site (but as I have no links to the testcontactus.php I thought it best rather than trying on a local server as I am not too savvy with that).

I don’t mind giving you the whole code of the page, so if these things don’t work I will be more than happy to share it, unless there is a reason I shouldn’t.

Thank you.

#6

Firstly, yes, I had been checking that all file names were correct and correctly related to each other on my server, and it had worked in Microsoft Edge. I also knew to refresh pages and on occasion even emptied caches or closed and reopened the browser.

So I did what was suggested and I removed the encryption type in the submit, the id= and the form identification from each form entry.

The result is that in all browsers I have tried (all but Safari but will have to check that tomorrow on my partner’s iPhone as I don’t use Apple) I get the message now as if it was successful.

BUT I no longer get an email to either my inbox or junk.

So it seems that the code has given me a ‘success’, but unlike in the past when I saw this page in Microsoft Edge, I no longer actually get the email promised (I did before i.e. the success message corresponded to getting an email).
Even in Microsoft Edge I get the success ‘THANK YOU’ message, but now no email.

So, if you don’t mind, could you look at the code on the main contactus page and see whether I removed something I shouldn’t have or need something changed please?

I have to thank you very much for taking the time with a novice.

The code for the contactus.php:

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MY WEBSITE CONTACT PAGE</title>
<link href="styles/selltosam.css" rel="stylesheet">
<style>
a:link {
    color: #2E2E2E;
    text-decoration: none;
}
a:visited {
    text-decoration: none;
    color: #2E2E2E;
}
a:hover {
    text-decoration: none;
    color: #000000;
    font-weight: 500;
}

a:active {
    text-decoration: none;
    color: #2E2E2E;
}
</style>
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.--><script>
var __adobewebfontsappname__="dreamweaver"

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script><script src="http://use.edgefonts.net/montserrat:n4:default;source-sans-pro:n2:default;basic:n4:default;bree-serif:n4:default;cabin:n4:default;convergence:n4:default;adamina:n4:default;alice:n4:default;droid-sans-mono:n4:default.js"></script>
	</head>
<body>
  <p><u><span style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 400;">back to <span style="font-weight: 600">Home</span></span></u></p>

  <section id="mainContent"> 
        

<div id="contactusform">
  <p><br>
    Please fill out the form below and I will contact you as soon as possible at a time that best suits you.</p>
</div>
<form action="newtestacknowledge.php" method="post" id="ContactForm">
    <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 300; font-size: large;">
     	      <label for="Name">*Name:</label>
     	      <input name="Name" type="text" required="required" size="50" maxlength="80">
   	          <label for="email"><br>
   	            <br>
              *Email:</label>
              <input name="Email" type="email" required="required" size="40" maxlength="60">
              <label for="tel"><br>
                <br>
                Phone:</label>
     	      <input name="Phone" type="tel" size="30">
     	   &nbsp;</p>
     	    <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
     	      <label for="timezone">Time Zone:</label>
     	      <select name="timezone">
     	        <option>Eastern</option>
     	        <option>Central</option>
     	        <option>Mountain</option>
     	        <option>Pacific</option>
     	        <option>Alaska</option>
     	        <option>Hawaii</option>
     	        <option>Other</option>
				</select></p>

     	      <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
     	      <label for="callafter">Best Time to Call:&nbsp;</label>
              <select name="callafter">
    <option value="00:00">12.00 AM</option>
    <option value="01:00">01.00 AM</option>
    <option value="02:00">02.00 AM</option>
    <option value="03:00">03.00 AM</option>
    <option value="04:00">04.00 AM</option>
	<option value="05:00">05.00 AM</option>
    <option value="06:00">06.00 AM</option>
    <option value="07:00">07.00 AM</option>
    <option value="08:00">08.00 AM</option>
    <option value="09:00" selected="">09.00 AM</option>
    <option value="10:00">10.00 AM</option>
    <option value="11:00">11.00 AM</option>
    <option value="12:00">12.00 PM</option>
    <option value="13:00">01.00 PM</option>
    <option value="14:00">02.00 PM</option>
    <option value="15:00">03.00 PM</option>
    <option value="16:00">04.00 PM</option>
    <option value="17:00">05.00 PM</option>
    <option value="18:00">06.00 PM</option>
    <option value="19:00">07.00 PM</option>
    <option value="20:00">08.00 PM</option>
    <option value="21:00">09.00 PM</option>
    <option value="22:00">10.00 PM</option>
    <option value="23:00">11.00 PM</option>
</select>
             
	<label for="callbefore">to</label>
	<select name="callbefore">
	  <option value="01:00">01.00 AM</option>
	  <option value="02:00">02.00 AM</option>
	  <option value="03:00">03.00 AM</option>
	  <option value="04:00">04.00 AM</option>
	  <option value="05:00">05.00 AM</option>
	  <option value="06:00">06.00 AM</option>
	  <option value="07:00">07.00 AM</option>
	  <option value="08:00">08.00 AM</option>
	  <option value="09:00">09.00 AM</option>
	  <option value="10:00">10.00 AM</option>
	  <option value="11:00">11.00 AM</option>
	  <option value="12:00">12.00 PM</option>
	  <option value="13:00">01.00 PM</option>
	  <option value="14:00">02.00 PM</option>
	  <option value="15:00">03.00 PM</option>
	  <option value="16:00">04.00 PM</option>
	  <option value="17:00">05.00 PM</option>
	  <option value="18:00">06.00 PM</option>
	  <option value="19:00">07.00 PM</option>
	  <option value="20:00" selected="">08.00 PM</option>
	  <option value="21:00">09.00 PM</option>
	  <option value="22:00">10.00 PM</option>
	  <option value="23:00">11.00 PM</option>
	  <option value="00:00">12:00 AM</option>
	  </select>
            </p>
     	    <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
     	      <label for="Comments">*Comments/Questions:<br>
     	      </label>
              <textarea name="Comments" cols="55" rows="6" required="required"></textarea>
              <br>
   	      </p>
     	    <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: oblique; font-weight: 300; font-size: medium;">*required</p>
     	    <p>
     	      <input name="reset" type="reset" value="reset">
     	      <input name="submit" type="submit" value="submit">
     	    </p>
     	  </form>
<br>
</section>


<footer>
  <p><span style="color: #212A49"><span style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif"><a href="index.html">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="privacy.html">Privacy Policy</a>
	<br>
	  <span style="font-size: small">Copyright 2019 RLWalker</span> </span> </span>
</p>
 
</footer>
	</body>
	
	
</html>
#7

and just in case you wish to see the code again for the action php script here it is again:

<?php
if(isset($_POST['submit'])) {
	
$to = ' "MYNAME" <me@email.com>';
$visitor_email = $_POST['Email'];
$subject = 'New Submission from SYHTS Contact Form';
$message = 'Name: '. $_POST['Name'] . "\r\n\r\n";
$message .= 'Email: '. $_POST['Email'] . "\r\n\r\n";
$message .= 'Phone: '. $_POST['Phone'] . "\r\n\r\n";
$message .= 'Time Zone: '. $_POST['timezone'] . "\r\n\r\n";
$message .= 'Call After: '. $_POST['callafter'] . "\r\n\r\n";
$message .= 'but Before: '. $_POST['callbefore'] . "\r\n\r\n";
$message .= 'Comments: '. $_POST['Comments'];
$headers = "From: info@mywebsite.com \r\n";
$headers .="Reply-To: $visitor_email \r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8';
$success = mail($to, $subject, $message, $headers, '-fme@email.com');
}

 function IsInjected($str)
    {
      $injections = array('(\n+)',
                  '(\r+)',
                  '(\t+)',
                  '(%0A+)',
                  '(%0D+)',
                  '(%08+)',
                  '(%09+)'
                  );
      $inject = join('|', $injections);
      $inject = "/$inject/i";
      if(preg_match($inject,$str))
        {
        return true;
      }
      else
        {
        return false;
      }
    }

    ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php if (isset($success) && $success) { ?>
<h1>Thank you</h1> Your message has been sent.
<?php } else { ?>
Sorry, there was a problem sending your message.
<?php } ?>

</body>
</html>
#8

If you are receiving the success message, it means that the mail() function returned a true value.

Check your spam/junk mail folder at the receiving To: email address.

Beyond that, you need to make sure that the To: and From: email addresses are correct. A huge problem occurs when people use a From: email address that doesn’t directly or indirectly (through an SPF DNS record) correspond to the sending mail server.

1 Like
#9

Okay, I decided to try to put things back. All the way to what I thought was the original form (I even pasted from the original post here to make sure) and with that I get the ‘success’ message on Microsoft Edge, and the failure notice in the others, but no emails at all now.

As stated, the last full page of code I have pasted and the latest php action file mean that I get a success message on all browsers but no emails at all.

#10

I am sorry I keep posting but trying different things, but must go off for the night.
I went back to the files that worked on Microsoft Edge (there are a few other errors in the code in regards to wasted lines as it was before I made all those syntax changes). I wanted to do it as an exercise to see what suddenly made the success message appear, but yet I also wanted to maintain the email success of Microsoft Edge.
Simply put, when I removed the formenctype=plain/text from the submit. This then allows the success message to appear on all results pages, but only Edge actually sends an email.

I have to head off for the night unfortunately, but what I will do tomorrow is remove all the syntax errors again one by one and still ensure that the email is being sent with Microsoft Edge.
Once I have it cleaned up, then I can try each item, remove id alone, remove form id alone and see if any of these make it work in its entirety.
Removing the formenctype seems to ‘help’ in creating a success message, but I don’t know why emails are not sent despite this.
I also don’t know why emails stopped via Edge, so this is what I will explore.

It may be later tomorrow when I can get this all done, so I thank you for your patience while I try these things out.
Again, I apologise for all the messages as I reported back.

#11

My apologies as I did not see you latest reply

If you are receiving the success message, it means that the mail() function returned a true value.

Check your spam/junk mail folder at the receiving To: email address.

Beyond that, you need to make sure that the To: and From: email addresses are correct. A huge problem occurs when people use a From: email address that doesn’t directly or indirectly (through an SPF DNS record) correspond to the sending mail server.

I am using an email address that I set up on the server using the domain name as I thought that this may be an issue. Would that be enough or are there settings I could check? Would this cause it to work in some browsers but not others though? And why would the changes stop the emails entirely?
I have also been checking my spam folders.

#12

I just checked my email again, and suddenly it is working in Chrome too.
My script has a number of syntax errors in it though and at this point I was using the older script in preparation for testing the removal of one thing at a time as described above.

So what I will do, is when I have time tomorrow evening, I will clean it up slowly and check each time.
Hopefully I will eventually end up with a cleaner code that still works. I am wondering whether there was a delay too, although I never had a delay before with Edge.
I am going to start id’ing each test submission with time and browser name as well.

I thank you for all of your help, and I hope that I can state that I have complete success once I go through the clean up. I will let you know if you don’t mind.

#13

I just wanted to update and say that it is all working now.
I think ensuring that all values and ids did not have any white space as well helped. Removing the encryption type in the submit, but NOT in the form beginning tag may have also helped: to note the latter did not work and I had to put it back in.

Thank you so much for your patience and I am sorry that I cannot say exactly what the problem was.

Now onto getting the other forms sorted. Trying to emulate everything in the same way.