Cannot Post contactform.php - php

I am not familiar with php. I have searched similar questions to where I could not find a solution. I followed a fairly simply tutorial to add a send email functionality to a web app but I cannot get it to work as I get this error when testing to send an email to my yahoo. I would like to ask for help in figuring out a solution and or how I can make this code better. Thanks in advance
This is my error
Cannot POST /contactform.php
Here is my form code from my index.html
<form action="contactform.php" method="post">
<div class="form-group">
<input type="text" name="name" placeholder="Full Name" class="form-control" id="name">
</div>
<div class="form-group">
<input type="text" name="email" placeholder="Email" class="form-control" id="email">
</div>
<div class="form-group">
<input type="text" name="subject" placeholder="Subject" class="form-control" id="message-text"></input>
</div>
<div class="form-group">
<textarea name="message" placeholder="Message" class="form-control" id="message-text"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-outline-dark">Send message</button>
</form>
And here is my contactform.php that is in the same folder as my index.html
<?php
if (isset($_POST['submit'])){
$name = $_POST['name'];
$mailfrom = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "myemail#yahoo.com";
$headers = "From: ".$mailfrom;
$txt = "You have received an email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsend");
}
?>

Related

Question about contact form HTTP ERROR 405 crash

so I am trying to make a link to contact form but it seems to be crashing and I do not know why is this happening. I double checked the link and variable name, but seems like error 405 happens without stopping every time I click.
This is my html part
<h3>Contact Form</h3>
<div class="containerofcontact" style="text-align: left !important;">
<form method="POST" action="contactform.php">
<label for="name">Name</label>
<input type="text" id="Name" name="Name" placeholder="Your name..">
<label for="email">Email</label>
<input type="text" id="Email" name="Email" placeholder="Your Email">
<label for="subject">Subject</label>
<textarea id="Subject" name="Subject" placeholder="Place Detail of Concern" style="height:200px"></textarea>
<input type="submit" value="Send">
</form>
</div>
This is php part
<?php
$name = $_POST['Name'];
$email = $_POST['Email'];
$text = $_POST['Subject'];
$mailTo = "blankforshare";
$headers = "From: ".$email;
$txt = "You have received an e-mail from ".$name."\n\n".$text;
mail($mailTo, $headers, $txt) or die("Error!");
header("Location: index.html");
?>
Thank you for the help.

Php mail not submitting and blank page displaying

I am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">

Email PHP form doesn't work [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I haven't written code in years, so I am going off old code from a project that is over 5 years old, so I am not surprised that it doesn't work; I would like some pointers on how to make it work, please.
Here is what I have in my HTML email form --
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
and here is what my PHP looks like --
<?php
if(isset($_POST['send'])) {
// Prepare the email
$to = ''foryourdayformals#gmail.com ';
$name = $_POST['contact_name'];
$mail_from = $_POST['contact_email'];
$subject = 'Message sent from website';
$message = $_POST['contact_message'];
$header = "From: $name <$mail_from>";
// Send it
$sent = mail($to, $subject, $message, $header);
if($sent) {
echo 'Your message has been sent successfully! Return to For Your Day, LLC Website';
} else {
echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). Return to For Your Day, LLC Website';
}
}
?>
Any help is GREATLY appreciated! Thanks!
update
$to = ''foryourdayformals#gmail.com ';
to
$to = 'foryourdayformals#gmail.com';
and need to add name attribute for form . This update your form
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary" name ="send">Send</button>
</form>

How to make a div visible after email is sent using PHP

I have the following contact form in my index.html file
<div class="alert alert-success visible" id="successmsg"><strong>Success!</strong> Your message has been sent to us.</div>
<form method="post" action="mail.php" class="contact-form">
<div class="form-group">
<input type="text" class="form-control" name="name" id="name" placeholder="Name">
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Email">
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject">
</div>
<div class="form-group">
<textarea class="form-control" type="text" name="message" id="message" placeholder="Message"></textarea>
</div>
<div class="actions">
<button type="submit" data-text="SUBMIT" class="button button-default"><span>SUBMIT</span></button>
</div>
</form>
The id "successmsg" is hidden in the HTML file using a simple display:none; code & I need to make it visible when the email is sent using the following php
<?php$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$formcontent=" Name:\r $name \n\n Email:\r $email \n\n Subject:\r $subject \n\n Message:\r $message ";
$recipient = "towersdvd#gmail.com";
$subject = "Website Contact";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader);
<style type="text/css">#lol{display:yes;}</style>
exit;}?>
This doesn't work at all. Can someone assist me with this? Really appreciate your kind help. Thanks in advance! :)
I think you are using/putting the wrong ID
Please change <style type="text/css">#lol{display:yes;}</style>
TO
<style type="text/css">#successmsg{display:inline;}</style>
Hope this will help.
There isn't any 'yes' value for the display property. Try changing it to {display: block;} or {display: inline;} depending.
Check this link for more info: https://developer.mozilla.org/en-US/docs/Web/CSS/display

PHP form submission returns blank

I'm a total novice so please bear with me :)…I've managed to create a form and used PHP to send the data to an email address. However, once I click submit; the screen goes blank instead of staying on the current page and displaying a message. I'm guessing i'm missing some sort of PHP code?
Also, i'd like to use the JQuery validator plugin on my form, how can I add it without basically screwing up the form?
MY HTML:
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
MY PHP:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
PHP script that you create will return an empty page, because that script just to send email. I think you need to combine PHP script and HTML script together with PHP script in top of script to get that you want and edit form action to empty like this sample:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
<div>
<form id="form_id" name="form_name" action="" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
Your form will take the user to scripts/index.php. You are echoing the '$feedback' var on the page with the HTML form. Redirect from scripts/index.php using
header("location: filelocation");
exit();
You can achieve this in two ways :
1. Have php and html code in one page.
2. Use ajax to submit your form.
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
</div>
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
echo '<p id="feedback">'.$feedback.'</p>'; <-- Notice this..
}
?>
You can also use ajax in jquery ($.ajax) or javascript.

Categories