1

I have been looking for a way to code on form submit so that the information will go to the server and then be sent directly to my email.

I have looked at various online tutorials and even changed which method I used when the first did not work. I have followed the instructions to the letter (I believe) but when I press submit, it takes me to the php page with the script but chooses to tell me that it could not send it and I also do not receive an email.

Some of the code added (such as -f email in the last header was part of the instructions if all else failed).

I am wondering whether it may be due to having set up the form in Dreamweaver so there are options such as 'required' already set. Should I be removing some of these additional settings for each entry and the submit button? I like that I can check the 'required' in Dreamweaver when setting up the forms as it make it easy and as I have a few different forms, then setting it here instead of adding additional validation codes in javascript or php is more straightforward.

I am just concerned that the setting automatically created in Dreamweaver may be negating settings in the php and javascript.

The only way I can think of asking is by including my form code, and then the php file code to see if I am missing something very simple.

My goal is simply to receive an email rather than having a person have to go through the mailto process and to also prevent spam and multiple emails. As you can see from those in the form, some are labelled 'required' and others aren't and I would like to keep these as they are if at all possible.

Please note that I have changed my emails to generic for privacy sake.

Form Code (in a file called Contactus.php - I had originally named it as an html file but then changed it to a php file)

<form method="post" id="ContactForm" action="testacknowledge.php">
    <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: bold; 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="Time Zone">Time Zone:</label>
              <select name="Time Zone" id="Time Zone" form="ContactForm">
                <option>Eastern</option>
                <option>Central</option>
                <option>Mountain</option>
                <option>Pacific</option>
                <option>Alaska</option>
                <option>Hawaii</option>
                <option>Other</option>
              </select>
              <br>
              <span style="font-style: normal; font-weight: 400; font-size:small">
            <p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
              <label for="Call Before">Best Time to Call:&nbsp;</label>
              <select name="Call After" id="Best Time" 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="Call Before">to</label>
    <select name="Call Before" id="Call Before" 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 my complete testacknowledge.php file which is named in the form action above:


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

$to = 'me@hotmail.com';
$subject = 'New Submission from 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['Time Zone'] . "\r\n\r\n";
$message .= 'Call After: '. $_POST['Call After'] . "\r\n\r\n";
$message .= 'Call Before: '. $_POST['Call Before'] . "\r\n\r\n";
$message .= 'Comments: '. $_POST['Comments'];

$headers .= "From: info@website.com\r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8';
    $email = filter_input(INPUT_POST, 'Email', FILTER_VALIDATE_EMAIL);
    if ($email) {
        $headers .= "\r\nReply-To: $email";
    }
$success = mail($to, $subject, $message, $headers, '-fme@hotmail.com');
}
?>


<!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>

On submit, the testacknowledge page opens and gives the "Sorry, there was a problem sending your message." and no email is received.

I apologise that this question seems to be asked a lot, but many did not use the above methods and so I could not find an answer that helped me. I appreciate everyone's time as I know how busy everyone is.

Thank you.

  • `mail()` returned `false`. You need to determine *why*. Check your mail logs and confirm with your host that you can send email and that they do not have special requirements for doing it. – John Conde Jul 05 '19 at 20:01
  • Thank you. I will look into this and check back here. Does the code in itself look like it should work as is? Do any of the settings in the form contradict - for some reason Dreamweaver allows settings for actions to be set in both the submit section as well as the overall form settings – Dragonwalker Jul 05 '19 at 20:20
  • I am sorry that this has been deemed a repeat, but I have been through the 'duplicate' post and the details there are still not fixing my issue. I have found that the form submits fine in Explorer, just not Chrome and Firefox. I have added another header (reply-to) but this hasn't helped either. Maybe it is something to do with the 'success'. Other php scripts don't seem to use this and I am wondering whether Chrome and Firefox don't like it for some reason. Error logs did not seem to show anything in regards to a form submission mail failure. My host allows emails, but not ext. SMTP – Dragonwalker Jul 06 '19 at 03:39

0 Answers0