"POST /mail.php" Error (404): "Not found" - html

I'm trying to make a simple contact form but I keep getting this error while trying to submit a response. The code is:
HTML :
<form action="mail.php" method="POST" class="submitphoto_form">
<input type="text" name ="name" class="wp-form-control wpcf7-text" placeholder="Your name">
<input type="mail" name="email" class="wp-form-control wpcf7-email" placeholder="Email address">
<textarea name="message" class="wp-form-control wpcf7-textarea" cols="30" rows="10" placeholder="What would you like to tell us"></textarea>
<input type="submit" value="Submit" class="wpcf7-submit">
</form>
PHP :
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "shaliniguha2#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-
decoration:none;color:#ff0099;'> Return Home</a>";
?>
Both the files are in the same folder.

There are three possibilities you get this error message
A) File name is not valid that you have (check case insensitivity)
B) Extension is invalid or not mentioned
C) File path is incorrect (check cases and double check file presence)

You need to configure your apache server locally if you are not working on a server because php scripts runs only on a server environment where php is installed.
In case you have apache server installed already, check if its running and your working directory is correct.

Related

Input type submit not redirecting to form action

I created a form that can send an email, but it is not redirecting to the php script when hitting submit.
Here is the form by the way
Code:
<form method="post" id="myForm" name="myForm" action="mail_handler.php">
<div class="row">
<div class="col-lg-12">
<div class="single-form">
<label>* FULL NAME</label> <input class="form-control" type="text" name="full_name" id="full_name" placeholder="Enter full name" required="">
</div>
</div><!-- Nice Select -->
<!-- First Name -->
<div class="col-lg-6">
<div class="single-form">
<label>* Email Address</label> <input class="form-control" type="email" name="emailAdd" id="emailAdd" placeholder="Enter email" required="">
</div>
</div>
<div class="col-lg-4">
<div class="single-form">
<input type="submit" name="submit" value="Submit" class="btn apply-btn mt-30">
</div>
</div>
</div>
</form>
and here is the mail_handler.php.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
if(isset($_POST['submit'])){
if(!empty($_POST['full_name']) && !empty($_POST['emailAdd'])){
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.mail.yahoo.com"; // sets yahoo as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "my username"; // yahoo username
$mail->Password = "my pass"; // yahoo password
$full_name = $_POST['full_name'];
$emailAdd = $_POST['emailAdd'];
$subject = "Webpage Client Feedback";
$to = "cremlicofficial#yahoo.com";
$subject = "WEBPAGE: PRE-APPLICATION";
$mail->From = "cremlicit#yahoo.com";
$mail->FromName = "CREMLIC ADMIN";
$mail->AddAddress("cremlic#yahoo.com");
$mail->AddCC('cegabrillo#yahoo.com.ph');
$mail->AddCC('ksgaro#yahoo.com');
$mail->Subject = "WEBPAGE:PRE-APPLICATION";
$mail->Body = "To Whom it may concern, \r\n"
. "A visitor submits a pre-application information, please see details below. \r\n \r\n"
. "Name: " . $full_name . " \r\n"
. "Email: " . $emailAdd;
$mail->AddEmbeddedImage('./images/1593998909.jpg', 'palogo', '1593998909.jpg');
if(!$mail->Send()) {
echo '<script type="text/javascript">alert("Message was not sent. \r\nMailer error: '.$mail->ErrorInfo.'");window.history.go(-1);</script>';
}
}else{
echo '<script type="text/javascript">alert("Error Occured! \r\nPlease fill up fields: Name, Address and Contact No.");window.history.go(-1);</script>';
}
}
?>
I am 100% sure that both HTML file and PHP script is on the same folder. Is there any problem with these line of codes?
The form is working fine, kindly check the location of mail_handler.php if its in the same folder or in different folder. Also share mail_handler.php code so we can check if there's any issue with the code.

How do I send an E-mail from a webpage?

I've been trying to learn the basics of HTML, and in doing this I've been designing my own rudimentary webpage. I don't plan on making it public at all, but it's good to help me to learn all of the different aspects of both HTML and CSS. In doing this, I've added a Contact section on one of the pages, that includes both an email address and a form that allows for an E-mail to be sent, I used one of the tutorials on W3Schools to create it. For the purposes of this I have removed my own email address, and replaced it with someone#example.com, but here is the output of this specific part of the code:
However, whenever I try to fill the form in to test it, I get this pop-up message. If I click cancel, then nothing happens, but if I click OK then then the mail app on my computer is opened. But the message that I typed into the form isn't there, and the E-mail address that I type into the box to send from is just changed to the default address on my computer.
So what can I do to prevent this pop-up message, and to just send the e-mail to me?
Here is the relevant code from the HTML document:
<h2 style = 'font-weight:normal'><a name = 'Contact' id = 'Contact'></a>Contact me:</h2>
<p>
You can reach me at: someone#example.com <br />
Or by just using the form below
</p>
<form action = 'mailto: someone#example.com' method = 'post' enctype = 'text/plain'>
<input type = 'text' name = 'name' placeholder = 'Name'> <br />
<br />
<input type = 'text' name = 'mail' placeholder = 'E-mail'> <br />
<br />
<input type = 'text' name = 'comment' size = '50' placeholder = 'Comment'> <br />
<br />
<input type = 'submit' value = 'Send'>
<input type = 'reset' value = 'Reset'>
</form>
If HTML isn't going to be enough to send an e-mail from a webpage, and I need another language to write a program that can do it, I am quite competent in Python, and I know C# to some extent. However, I've never used JavaScript, PHP, Perl, or anything else (I don't know what sort of languages would be appropriate)
If you want to submit the form to go to an email it's simple really. You could use a simple server-side language like PHP. You'll need 3 files. One file that houses the front-end form contents, one file that processes the form once the user hits the submit button and a thank you page after the form gets sent to let the user know that the form has been submitted. Here is a demo below.
HTML:
<form action="processor.php" method="post" id="myForm">
<label for="firstname"></label>
<input type="text" name="firstname" placeholder="First Name" id="firstname" required>
<label for="lastname"></label>
<input type="text" name="lastname" placeholder="Last Name" id="lastname" required>
<label for="email"></label>
<input type="email" name="email" placeholder="Email" id="email" required>
<label for="comments"></label>
<textarea rows="4" cols="32" name="comments" id="comments" placeholder="Questions & Comments"></textarea>
<input type="submit" value="Submit">
</form>
PHP (processor.php file)
/***********************************************************/
/******* Set the receipient email address below ********/
/******* And set the subject line of the email ********/
/*$recipient_email = "testemail#yahoo.com";*/
$recipient_email = "testemail#yahoo.com";
$email_subject_line = "Mail from Website";
/***********************************************************/
/***********************************************************/
if(isset($_POST['firstname']))
{
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
$email = $_POST['email'];
$comments = $_POST['comments'];
if(!empty($firstName) &&
!empty($lastName) &&
!empty($email) &&
!empty($comments))
{
$message = "Name: $firstName, Lastname: $lastName, Phone: $phoneNumber,
Email: $email, Comments: $comments";
send_mail($email, $message, $recipient_email, $email_subject_line);
}
}
function send_mail($email, $message, $recipient_email, $email_subject_line)
{
$to = $recipient_email;
$from = $email;
$subject = $email_subject_line;
$headers = "From: {$email}" . "\r\n" . 'Reply-To:' . $email . "\r\n" . 'X-
Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
header("Location:thankyoupage.php");
thankyoupage.php (After data has been submitted)
<div class="thankyoucontainer">
<h1>Thank you, your message has been submitted.</h1>
Go back to home page
</div>

HTML mailto form

Can anyone help me with my feedback form for a website I am building?
I am not receiving any errors when I run this, although it doesn't actually send any email at all.
The following is the code I am trying to use:
<form action="mailto:admin#example.com" enctype="text/plain" method="post">
<p>Name: <input name="Name" type="text" id="Name" size="40"></p>
<p>E-mail address: <input name="E-mail" type="text" id="E-mail" size="40"></p>
<p>Comment:</p>
<p><textarea name="Comment" cols="55" rows="5"
id="Comment"></textarea></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
Sending mail from HTML Form is not a right option to do, you are using an HTTP Method (POST), so you have to set a http/https link from your action value. Otherwise, you have to send the email using the href tag, including a subject and body parameters.
E.g: Send Message
The mail application installed in your machine would automatically opened when you click that link.(Outlook, Gmail,...) and you can choose which one you have to send the mail within it.
you should maken a .php file
eg.
<form method="post" action="mail.php">
then in your mail.php put something like this:
<?php
session_start();
$to = "contact#webmagico.be"; // this is your Email address
$from = htmlspecialchars($_POST['email']); // this is the sender's Email address
$naam = htmlspecialchars($_POST['naam']);
$email = htmlspecialchars($_POST['email']);
$messageText = $naam . " " . $email . " wrote:" . "\n\n" . htmlspecialchars($_POST['bericht']);
$message = array(
"ontvanger" => $to,
"zender" => $from,
"naam" => $naam,
"email" => $email
);
$valid = true;
foreach($item in $message)
{
if(!isset($item) || $item === "")
{
$valid = false;
}
}
if($valid)
{
mail($to, $naam, $message, "From:" . $email);
}
else
{
$_SESSION['error'] = "Forgot something!"
}
/*file that gives the response*/
header('Location: thankyou.php');
?>
You can find different alternatives about a post-form on the web.
Hope this helps.

How to submit a contact form via custom button using "href" code?

For my website I'm working on a contact form, which works. But I want the submit button to be like other buttons on my site, meaning I want it to be styled like the code below.
However, I can't get it to submit via a "href" code.
I've tried applying answers on similar questions but haven't had any luck.
Any help would be greatly appreciated!
THE STYLE FOR THE SUBMIT BUTTON I WANT TO USE:
<div class="section-buttons">
<p class="button layer" data-depth="0.10" ><a href = "I WANT THIS TO SUBMIT THE FORM"
class="y1 knop roll swing"><span class="g1">SUBMIT</span><span class="g2">SUBMIT</span>
</a></p>
</div>
THE FORM CODE:
<form action="form.php" method="post" enctype="multipart/form-data">
<label></label>
<input name="name" required placeholder="Name">
<label></label>
<input name="email" type="email" required placeholder="E-mail">
<label></label>
<textarea name="message" cols="20" rows="5" required placeholder="Message">
</textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
EDIT:
Thanks a lot for the quick replies. Really appreciated.
Celt, your solution definitely brings me close to the solution.
It does indeed bring me to the form.php but it doesn't seem to submit the actual data to an email address.
Could it be that my PHP file (forms.php) does something wrong with the new code? I'm guessing the last part "if ($_POST['submit'])" doesn't quite work with this new approach? Any help?
Sorry for the noobness.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website.com';
$to = 'email#email.com';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message
again.</p>';
}
}
?>
This should work for you:

How to create simple contact form?

I found this example on w3schools and change email to my email, but when I click Send nothing happens. Where is the problem?
<h3>Send e-mail to someone#example.com:</h3>
<form action="MAILTO:someone#example.com" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name" value="your name"><br>
E-mail:<br>
<input type="text" name="mail" value="your email"><br>
Comment:<br>
<input type="text" name="comment" value="your comment" size="50"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
Don't do this. It is unreliable as it depends on the mail client the user has installed and you can not test for that.
instead you should either post the form data to a php script that uses the
php mail() function - which is easy to learn
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = $_POST['comment'];
$headers = 'From:'. $_POST['email']. "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
or use a cgi script like
http://www.response-o-matic.com/
You aren't really sending the email when you use the mailto:someone#example.org All you're doing is telling the browser that it should handle what follows as an email address and so, the browser will open the default mail client.
The only way to send an email programmatically, which I think is what you are trying to do, is to use a server side script. Something like PHP or ASP.NET to just give two examples.