0

I am trying to execute php with a html form but I get the following output to the console.

[Fri Sep 18 13:04:38 2020] [::1]:59753 Accepted

[Fri Sep 18 11:04:38 2020] [404] /php/contactform-process.php - No such file or directory [Fri Sep 18 13:04:38 2020] [::1]:59753 [404]: POST /php/contactform-process.php - No su ch file or direc tory

[Fri Sep 18 13:04:38 20 20] [::1]:59753 Closing

This is my code

<?php 
    if(isset($_POST['submit'])){
        $to = "myemail@gmail.com";
        $from = $_POST['email'];
        $subject = $_POST['subject'];;
        $message = $_POST['message'];
        var_dump($to);
        var_dump($from);
        var_dump($subject);

        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
    }
?>

<!-- Contact Form -->
<div class="col-lg-6">
    <form id="ContactForm" data-toggle="validator" action="" method="post">
        <div class="form-group">
            <input type="email" name="email" class="form-control-input" id="cemail" placeholder="Email" required>
            <div class="help-block with-errors"></div>
        </div>
        <div class="form-group">
            <input type="text" name="subject" class="form-control-input" id="csubject" placeholder="Subject" required>
            <div class="help-block with-errors"></div>
        </div>
        <div class="form-group textarea">
            <textarea type="text" name="message" class="form-control-textarea" id="cmessage" placeholder="Write your message here"></textarea>
            <div class="help-block with-errors"></div>
        </div>
        <div class="form-group">
            <input type="submit" value="Submit" class="form-control-submit-button"></input>
        </div>
        <div class="form-message">
            <div id="msgCSubmit" class="h3 text-center hidden"></div>
        </div>
    </form>
</div>

I am using vscode with the php server plugin. I am running PHP 7.4

anonymous-dev
  • 2,897
  • 9
  • 48
  • 112
  • Are you using javascript/ajax to post the form? – Levi Cole Sep 18 '20 at 11:36
  • No, should I? I thought that this was built in to the form. From what I read here https://stackoverflow.com/questions/18379238/send-email-with-php-from-html-form-on-submit-with-the-same-script – anonymous-dev Sep 18 '20 at 11:41
  • No javascript isn't required. I was just wondering because your html form doesn't include an `action` value which would normally mean it submits to the same file/url. But the error you've given appears as though the form is attempting to submit to `/php/contactform-process.php` instead. – Levi Cole Sep 18 '20 at 11:45
  • _“But in the question I referenced is clarified that action with a php file doesn't work in html5”_ - what are you talking about? Of course specifying the URL to a PHP script in the action attribute works and is allowed in HTML5 … – CBroe Sep 18 '20 at 12:13
  • @CBroe I removed my last comment. I miss read. Anyway I tried both ways with and wihout an action and it gave the same result. – anonymous-dev Sep 18 '20 at 12:18
  • This must have something to do with your IDE/development setup then. – CBroe Sep 18 '20 at 12:23
  • I tried the code in a seperate index.php and it works with the same IDE/development setup. – anonymous-dev Sep 18 '20 at 13:31

1 Answers1

0

Your code is ok! Please check other javascript/jquery plugins or change your browser some times some of the extensions in Google chrome create such kind of errors. Thanks! Have a nice day.

Sajjad Ali
  • 84
  • 6