I've been away from Markup Language for several years so I'm worse than rusty. I'm trying to make a form that will come to my email address when sent. I can get it up on the website, but it gives me a 404. I'm doing something wrong, but not sure what it is. It may be the PHP at the top. I'm including the markup. Any assistence appreciated. Thanks.

<form name="htmlform" method="post" action="html_form_send.php">
<table width="475px">
</tr>
<tr>
<td valign="top">

<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="50">
</td>
</tr>

<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="50">
</td>

</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="45" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
<form action="MAILTO:giddyupgilbert@comcast.net">
</td>
</tr>
</table>
</form>

Dani AI

Generated

correctly flagged broken markup and the stray second form, and was right to ask whether the server-side script actually exists. The 404 on submit is almost always one of these: the handler file path/name is wrong (case matters on Linux), the host does not run PHP (static hosts like GitHub Pages), .htaccess or rewrite rules intercept the request, or file permissions/ownership prevent access. A quick checklist will find the problem fast.

First, repair the HTML so there is exactly one well-formed <form>. Remove the MAILTO: form (mixing mailto and server handlers is unreliable) and fix any stray quotes or mismatched tags — even a single extra quote in an attribute can break parsing. Then test the handler directly in the browser and from the server side:

curl -I https://yourdomain.example/path/html_form_send.php

Also submit the form while watching the Network tab in developer tools to confirm the exact request URL and response code. If the direct URL gives 404, the file is missing or the path is wrong.

If the site supports PHP, use a server-side handler to assemble and send the email (don’t rely on mailto). Example minimal handler (place as the action target):

<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); exit; }

$first = htmlspecialchars(trim($_POST['first_name'] ?? ''), ENT_QUOTES, 'UTF-8');
$last  = htmlspecialchars(trim($_POST['last_name'] ?? ''), ENT_QUOTES, 'UTF-8');
$email = filter_var($_POST['email'] ?? '', FILTER_VALIDATE_EMAIL);
$comments = htmlspecialchars(trim($_POST['comments'] ?? ''), ENT_QUOTES, 'UTF-8');

if (!$email) { http_response_code(400); exit('Invalid email'); }

$to = 'giddyupgilbert@comcast.net';
$subject = "Message from $first $last";
$body = "Name: $first $last\nEmail: $email\n\n$comments\n";
$headers = "From: no-reply@yourdomain.example\r\nReply-To: $email\r\n";

if (mail($to, $subject, $body, $headers)) echo 'OK'; else { http_response_code(500); echo 'Mail failed'; }
?>

Notes and next steps: ensure PHP is enabled (create a phpinfo test file), set correct file permissions (644 files, 755 folders) and use a domain-based From address to avoid spam filtering. For reliable delivery and authentication use an SMTP library like PHPMailer instead of raw mail() (PHPMailer, PHP mail() docs).

Recommended Answers

All 4 Replies

You have a large number of errors. I went through and indented it to make it lot easier to read. In short, your opening and closing tags are all screwed up, and you have to form actions, and two closing form tags. I'm not sure what that second form action is supposed to be.

Make sure that your path to the php file is correct in the first form action. It is pointing to the same folder that the file that holds the form is in. There maybe even more problems that I missed but I am getting ready to head to bed :)

<form name="htmlform" method="post" action="html_form_send.php">
    <table width="475px">

        <tr>
            <td valign="top">
                <label for="first_name">First Name *</label>
            </td>
            <td valign="top">
                <input type="text" name="first_name" maxlength="50" size="50">
            </td>
        </tr>

        <tr>
            <td valign="top"">
                <label for="last_name">Last Name *</label>
            </td>
            <td valign="top">
                <input type="text" name="last_name" maxlength="50" size="50">
            </td>
        </tr>

        <tr>
            <td valign="top">
                <label for="email">Email Address *</label>
            </td>
            <td valign="top">
                <input type="text" name="email" maxlength="80" size="50">
            </td>
        </tr>

        <tr>
            <td valign="top">
                <label for="telephone">Telephone Number</label>
            </td>
            <td valign="top">
                <input type="text" name="telephone" maxlength="30" size="50">
            </td>
        </tr>

        <tr>
            <td valign="top">
                <label for="comments">Comments *</label>
            </td>
            <td valign="top">
                <textarea name="comments" maxlength="1000" cols="45" rows="6"></textarea>
            </td>
        </tr>

        <tr>
            <td colspan="2" style="text-align:center">
                <input type="submit" value="Submit">
            </td>
        </tr>

    </table>
</form>

<form action="MAILTO:giddyupgilbert@comcast.net">

You are likely getting a 404 because when the form is submitted, the action specifies this page: html_form_send.php

Does that page exist?

Not sure why you have another form element towards the bottom with the mail to.

I actually want it to go to an email, not to a web page. When I take the PHP out it will bring up my email client addressed to the right email, but there is none of the info that was typed in. When I take the email off, of course, the PHP will then give the 404 error. I've replaced the PHP with email info and still getting the 404 error. So, I'm inputting something incorrectly.

I imagined you were sending the form data over to PHP to send the email to you, this is the typical behavior. If you're getting a 404 for the PHP, then it is because the path in the form action for the PHP file is incorrect.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.