Skip to main content
Known Participant
June 27, 2024
Question

Contact form problem, html and php

  • June 27, 2024
  • 3 replies
  • 1912 views

I am using Dreamweaver cc for the following simple contact form which is saved in index.html and I created a mail.php file both saved to -public.html along with styles.css (server is Hostgator.)

 

The form is simple but looks fine, but the form will not send.

{"code":"MethodNotAllowed","message":"POST is not allowed”}                                                                      see mail.php below:

 

Can someone please advise me on what I have done incorrect?

index.html

<!-- fourth container contact section -->

        <div class="container-fluid bg-2 text-center" id="Contact">

            <div class = "container">

                <div class = "contact-content flex">

                <div class = "contact-left">

                <div class="title">

                <h3 class="ontop">Contact</h3><br>                        

</div>

                        

        <form action="mail.php" method="post">

        <input type = "text" class = "form-control" placeholder="Your name here ...">

        <input type = "email" class = "form-control" placeholder="Your email here">

<br>

        <input type = "submit" class = "btn-submit btn" value = "Submit">                        

</form>

</div>      

<!-- end of contact section —>

 

 

Mail.php file

I have the following code from https://www.php.net/manual/en/function.mail.php, but not sure how to change it to fit my simple form.  I have tried changing it to suit the contact form details:  $to to $text = ‘Your name here’, $subject to $email=‘Your email here’ and $message to $Submit, $headers=‘I used my website.com' and ‘Reply-To: myemail@HostGator.com, but once saved and pressed submit, it opens into a new window with a message {"code":"MethodNotAllowed","message":"POST is not allowed"}

 

<?php

$to      = 'nobody@example.com';

$subject = 'the subject';

$message = 'hello';

$headers = 'From: webmaster@example.com' . "\r\n" .

    'Reply-To: webmaster@example.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

 

mail($to, $subject, $message, $headers);

?>

 

I have contacted HostGator who said that it was not their problem and could not help and that I should contact the web developer, but as I am putting my own website together then that advice was not useful for me.

I hope someone can give me some help on this.

Thank you

    This topic has been closed for replies.

    3 replies

    BenPleysier
    Brainiac
    June 29, 2024

    May I suggest another option to make life easier?

     

    If you take out a one month subscription of Basic Wappler, you will have plenty of time to create the contact form complete with 'send-mail'. No coding required. 

     

    After that , when there is no need for Wappler, you can use the likes of Dreamweaver, or better, Visual Studio Code to maintain the site.

     

    For a turorial, see:

    https://youtu.be/xVZx7aaz2Gs?si=L1RtyrXTw8GjW_QG

    Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
    Brainiac
    June 29, 2024

    I'd say you'll probably need longer than a month to open Wappler and understand its workflow.......It's not for the faint hearted in my opinion............just search for a secure php script and youre done rather than trying to learn a complex environment in a limited amount of time, if its just a simple form you need.................on the other hand if you have unlimited amounts of time to dedicated to learning and deep pockets then Wappler might be your ideal weapon of choice.

     

    Brainiac
    July 1, 2024

    I do have time, and really don't want to throw money here and there if I can use text books, online resources, etc.   I am now working with this tutorial: https://www.phptutorial.net/php-tutorial/php-contact-form/

    HTML Dog is pretty good, but no PHP help.

    Thank you!

    Best regards

    Sheila


    It's probably a little overly complex for my liking and makes php look a bit difficult for anyone new to php..........but at least its sanitizing the form inputs which is highly important but it uses the php mail function to send the information which is fine, given the data has been properly sanitized, providing your host allows the mail function to be used.

     

    A lot of hosts had issues with unsanitized data being trafficked through an unprotected form built by greenhorns so they stopped providing the php mail function by default and suggested using phpMailer which is more robust in the hands of greenhorns, but more complex to configure.

    Brainiac
    June 28, 2024

    Initially you should check to see if HostGater will allow the php mail() function to be used on their servers. Some hosts don't, in fact many don't.

     

    The form will never work as you have no 'name' attribute specified in the form tags. php needs that to get the information from the input fields.

     

      <input type = "text" class = "form-control" placeholder="Your name here ...">

            <input type = "email" class = "form-control" placeholder="Your email here">

     

      <input type = "text" class = "form-control" name="name" placeholder="Your name here ...">

            <input type = "email" class = "form-control" name="email" placeholder="Your email here">

     

    Your php script should then grab the name and email input using the $_POST method.

     

    $name = $_POST['name'];

    $email = $_POST['email'];

     

    However just doing that leaves the form very unsecure. You need to sanitize form input data.

     

    I would advise you Google for a secure php script if you are not a coder. 

     

     

     

     

    sxs726Author
    Known Participant
    June 28, 2024

    Thank you very much for your feedback and that missing 'name' atrribute.  I am not a coder, but I did take a course in html coding over 35 years ago on a wang.  I have Adobe cc and decided to do my own website than outsourcing it and have been using HTML Dog 2006 by Patrick Griffiths  and the internet, plus Adobe Community.  So every liitle bit of help is most appreciated. 

    Best regards

    Sheila

    Inspiring
    June 28, 2024

    How many submissions are we talking about (per month)? And can you explain a bit more of your setup or share a URL? You might be better with just a simple free plan from a typeform/jotform/etc, or one tied to a platform like hubspot, or if you are using a CMS like Wordpress, there are plugin options that may be available to you as well.

    Nancy OShea
    Brainiac
    June 27, 2024

    Ask Hostgator which contact form-processing script they recommend. 

    Some hosts have scripts on their servers you can use; others don't.

    It varies by hosting provider and the servers they use.

     

    PHP Mailer is the one that's most often recommended by hosting providers.  It's safe, secure and won't allow hackers to exploit your forms & server into a spam relay.

    https://github.com/PHPMailer/PHPMailer

     

    Hope that helps.

     

    Nancy O'Shea— Product User, Community Expert &amp; Moderator
    sxs726Author
    Known Participant
    June 28, 2024

    Thank you very much for you reply and information. I have checked with HostGator and they recomment PHP Mailer, but unfortunately they do no provide scripts or support on scripts.  I will join GitHub and see if I can get savvy with PHPMailer.  

    Best regards

    Sheila

    Nancy OShea
    Brainiac
    June 28, 2024

    Start with this Simple Contact Form example.  Copy & paste code into a new PHP document and saveAs contact_form.php. 

    NOTE: This is a one-page form & script combined.

    https://github.com/PHPMailer/PHPMailer/blob/master/examples/simple_contact_form.phps

     

    Nancy O'Shea— Product User, Community Expert &amp; Moderator