• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Contact form problem, html and php

Community Beginner ,
Jun 27, 2024 Jun 27, 2024

Copy link to clipboard

Copied

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

Views

274

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 27, 2024 Jun 27, 2024

Copy link to clipboard

Copied

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 & Moderator
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 28, 2024 Jun 28, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2024 Jun 28, 2024

Copy link to clipboard

Copied

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 & Moderator
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2024 Jun 30, 2024

Copy link to clipboard

Copied

Sorry didn't see this, thank you for the details, I will check it out now. I have already downloaded PHPMailer as you suggested from github and have it in my server file.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 28, 2024 Jun 28, 2024

Copy link to clipboard

Copied

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. 

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 28, 2024 Jun 28, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2024 Jun 28, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2024 Jun 30, 2024

Copy link to clipboard

Copied

Hello,

Submissions, not too sure.  

Form

HTML 

<!-- fourth container contact-form section -->

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

<div class = "container">
<div class = "contact-content flex">

<div class="title">
<h3 class="ontop">Contact</h3><br>
</div>
<form id="contactform" class="form-control" method="post" action="contactform.php">
<input type="text" class = "form-control" name="name" placeholder="Your name here ...">
<input type="email" class = "form-control" name="email" placeholder="Your email here">
<br>
<input type = "message" class = "form-control" name="message" placeholder="Your message here...">
<br>
<input type="submit" class="btn-submit btn" value="Submit">
</form>

 

PHP

contactform.php is still in progress, I am now using https://www.phptutorial.net/php-tutorial/php-contact-form/ as guidance) . 

 

Thank you for your response, hopefully the above guidance will get the form to work.

Best regards

Sheila

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2024 Jun 28, 2024

Copy link to clipboard

Copied

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. 

BenPleysier_0-1719625505627.png

 

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, the only real Dreamweaver alternative.
You can send form data to email thanks to the mailer component integrated in Wappler. This is useful for contact forms, inquiry forms, reservation forms or any other form which data needs to be sent to an email.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 29, 2024 Jun 29, 2024

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2024 Jun 29, 2024

Copy link to clipboard

Copied

Useful information from someone that has never tried Wappler.

 

 

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 29, 2024 Jun 29, 2024

Copy link to clipboard

Copied

I think its reasonable to assume that doing anything in an environment that is unfamiliar will be lengthy and frustrating when there are simpler alternatives.

 It seems a little crazy to me to put yourself through a steep learning curve to create a one off component. It's better reserved in my opinion if youre going to make that environment your primary approach to creating applications as a whole, then the time and expense would be justifiable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2024 Jun 30, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2024 Jun 30, 2024

Copy link to clipboard

Copied

Thank you for your response, good idea about a one month subscription, but I do have time so will give that a miss.

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines