简体   繁体   中英

404 error on localhost

I am trying to use some ajax to send some email. I have done this before using cold fusion and had no issue.

What I am running into is that localhost is not finding a file that is clearly in the directory. In fact the file sits in the same directory as index.php which is finds no problem. However it gives me a 404 error file not found on my send.php file. I have even tried to go directly to the page via the address bar and it does not find the file. If I put in the file path ie - file:///C://xampp/htdocs/3H-Web-Wlements/send.php it will display the code.

However when I upload to my active server it has no issues.

What am I missing here?

Here is the error from the log: [Wed Sep 23 19:33:34.295785 2015] [:error] [pid 2552:tid 1752] [client ::1:63670] script 'C:/xampp/htdocs/index.php' not found or unable to stat, referer: http://localhost/3H-Web-Wlements/

Do I have something mis-configured or even not configured?
Like I said. It works on my active server but fails on localhost only.

my send.php code

<?php
/*
 **************************************
 *                                    *
 * Config here                        *
 *                                    *
 **************************************
 */

$to = 'xxx@gmail.com';
$subject = 'Message from website';
$siteName = "xxx";

/*
 *************************************************************
 *                                                           *
 *      Don't Change below code, if you don't know php.      *
 *                                                           *
 *************************************************************
 */

$name = $_POST['contactName'];
$mail = $_POST['contactEmail'];
$subject = $_POST['contactWebsite'];
$note = $_POST['contactMessage'];
$ipAdd = $_POST['contactIp'];

if (isset($name) && isset($mail) && isset($note)) {


    // $mailSub = '[Contact] [' . $siteName . '] '.$subject;

    $body = 'Sender Name: ' . $name . "\n\n";
    $body .= 'Sender IP: ' . $ipAdd . "\n\n";
    $body .= 'Sender Mail: ' . $mail . "\n\n";
    $body .= 'Website: ' . $subject . "\n\n";
    $body .= 'Message: ' . $note;

    $message = $body;

    $header = 'From: ' . $mail . "\r\n";
    $header .= 'Reply-To:  ' . $mail . "\r\n";
    $header .= 'X-Mailer: PHP/' . phpversion();

    // mail($to, $mailSub, $body, $header);
    mail($to, $subject, $message, $headers);
}else{
    echo '0';
}
?>

Based on the error message you provided and the obscurity of the URL you are navigating to on localhost, I suspect the root cause of your issue stems from having two different document roots set up on your development server and production server.

If I'm right, this can be fixed by changing your development server's document root from C://xampp/htdocs/ to C://xampp/htdocs/3H-Web-Wlements/ . With this set, the server will attempt to serve index.php from 3H-Web-Wlements/ instead of from htdocs/ .

The document root setting can be set within Apache's configuration file typically called httpd.conf . If you're using a development setup like XAMPP or MAMP, you likely have a button in the control panel to get to httpd.conf.

The setting should look like this after the change:

DocumentRoot C://xampp/htdocs/3H-Web-Wlements/

After making the change, you will need to restart your web server for the changes to take effect.

Sending email functions on php is much better to test on active server than localhost because localhost needs to configure to support email functions while active server is already set up for this. I also experienced it.

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