简体   繁体   中英

My PHP code is not working

I need a little help. I am trying to get my PHP code (saved as a separate file named lulzy.php) to work but it just doesn't want to. What is it that I am doing wrong???

My goal is to get the users message directly into my e-mail inbox and right upon the user fills out my web form.

Here is the link to my JSFiddle: http://jsfiddle.net/8S82T/127/

And here is my PHP code:

<?php
  $name= $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "mymail@gmail.com", "Feedback Form Results",
    $message, "From: $email" );
  header( 'Location: Index.html' );
?>

Everything is in the same folder on my desktop.

This is the message I receive when I try to fill the whole form and send a message:

Firefox can't find the file at /C:/Users/MS/Desktop/Slide Down Contact Me Form/lulzy.php

You need to have name attribute on each of your form input's

<input type="text" name ="fullName" placeholder="Please enter your full name here" required />

Same for email and textarea , and method='post' instead of action='post'

Your php needs to be on your server not on your desktop.

You forgot to add name attributes:

<form action="lulzy.php" method="post">
        <h6><img src="img/person.png" alt="" /> Name</h6>

    <input name="name" type="text" placeholder="Please enter your full name here" required />
        <h6><img src="img/email.png" alt="" /> E-mail</h6>

    <input name="email" type="email" placeholder="Please enter your e-mail address" required/>
        <h6><img src="img/message.png" alt="" /> Message</h6>

    <textarea name="message" placeholder="Type your message..." required/></textarea>
    <input type="submit" value="Submit">
</form>

You need method="POST" instead of action="post"

your declaring action twice and not declaring your method at all of how the form is posting to your PHP script

You also for your name attributes like the other answers state

I think none of the answers here contain the actual solution for this error message:

Firefox can't find the file at /C:/Users/MS/Desktop/Slide Down Contact Me Form/lulzy.php

This implies that

  • you have opened your HTML from your local hard drive (instead of serving it from a local web server)
  • and you therefore don't have any PHP processor in there (though lulzy.php seems really to be non-existent in the specified folder)

Furthermore, you forgot to add name attributes to your form fields (as others have already mentioned here) and you declared the method attribute as the form's action by accident:

<form action="lulzy.php" action="post">

<!-- This should be right: -->
<form action="lulzy.php" method="post">


Use a captcha? (see OP's comment )
I would definitely add one if you keep your form sending direct emails. There are several libraries out there - depending on your traffic (private or commercial site?) - you might use reCAPTCHA . You could also roll your own, but better use intelligent questions or something only a human could solve instead of an image.

Nevertheless, you should also take your users into consideration. Possible spam beating vs. user experience .

A completely other option besides verifying human beings would be to not send the emails to your (personal) email address, save them to your database instead and create a simple notification system on your own. That way, you have more granular filter control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM