0

I created simple html page and I want to send email via php file and this is my js code for it

$.ajax({
    url: "././mail/contact_me.php",
   type: "POST",
    data: {
      name: name,
     phone: phone,
     email: email,
     message: message
   },

But when I try to send this request I got 404 NOT FOUND response in my browser. Is anyone have idea why it doesn't work? If you need more info about this projekt let my know in comment

In this photo you can find my project structure

enter image description here

Mateusz Sobczak
  • 1,551
  • 8
  • 33
  • 67
  • 3
    What do you expect from `././`? – u_mulder Jun 08 '19 at 13:50
  • 1
    Did you mean to use `..` which makes the relative path go up a directory? Eg `../../mail/contact_me.php` note if the js script is used in index.html and that is the root path for the site the path could just be `/mail/contact_me.php` – Patrick Evans Jun 08 '19 at 13:51
  • still doesn't work I changed to ../../mail/contact_me.php and move js to index.html but I still get 404 – Mateusz Sobczak Jun 08 '19 at 13:57
  • Note i just used ../.. as an example you need to use the correct relative path or use an absolute path, https://stackoverflow.com/questions/21306512/difference-between-relative-path-and-absolute-path-in-javascript/21306892 – Patrick Evans Jun 08 '19 at 15:11

3 Answers3

1

The url should just point to the /mail subdirectory.

$.ajax({
    url: "/mail/contact_me.php",
    type: "POST",
    data: {
        name: name,
        phone: phone,
        email: email,
        message: message
    }
}

Hope that helps :)

Julio María Meca Hansen
  • 1,303
  • 1
  • 17
  • 37
0

Use the full URL for the contact_me.php (ie: //example.com/contact_me.php). Relative paths are not going to work from JavaScript.

Dave
  • 5,108
  • 16
  • 30
  • 40
0

Try this

$.ajax({
url: "../mail/contact_me.php",
type: "POST",
data: {
       name: name,
       phone: phone,
       email: email,
       message: message
      },
 });