powering contact form with php - php

I am trying to power my contact form with the following HTML and PHP, and when I enter information and press enter, I always get an Error!
HTML
<form action="contact.php" method="POST">
<input type="text" placeholder="your name" name="name">
<input type="email" placeholder="Your Email" name="email">
<textarea placeholder="Your Message" name="message"></textarea>
<button type="submit">submit</button>
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Message: $message";
$recipient = "jainkenul#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
I have uploaded these files on my server, you can check it here

I don't see any error in your code. Probably, your host may have disabled the mail() function

Related

Stop form refreshing and duplicate emails sent from form

First of all I am wondering if there is a way to make it so the page don't refresh on form submission but the boxes etc. are still all cleared.
But my main issue is, once I submit a form it sends an email. BUT.... now every time I refresh the page or go back on the website it sends the email again. I can also click the submit several times. Any help is greatly appreciated.
Code
<?php
if(isset($_POST['SubmitButton'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "reviews#itssimplytech.co.uk";
$subject = "Simply Tech Contact Form";
$headers = "From: $email \r\n".
"Reply-To: $.email \r\n".
'X-Mailer: PHP/' . phpversion();
mail($recipient, $subject, $formcontent, $headers) or die("Error!");
}
?>
<form class="contact-form" action="" method="post">
<input type="text" name="name" placeholder="Name" required>
<input type="email" name="email" placeholder="Email" required>
<textarea rows="5" name="message" placeholder="Say Something..." required></textarea>
<input type="submit" name="SubmitButton" value="Submit">
</form> <!-- /.contact-form -->

Problems with PHP contact form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a problem with my contact form that I have created. When the user clicks on the send email button, I receive the email with a header, but I can't see the user's input.
So basically I am able to see the header($subject) and the pre written text("This is an automated message"), but I am not able to see the contents of $email and $message. What could be wrong?
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
you need to check whether you have post parameters then send the email
change your code to
<?php
if(isset($_POST['email']) && isset($_POST['message'])){
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
Try like this
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
$body= $_POST["message"]
if ($_SERVER["REQUEST_METHOD"] == "POST") {
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
This will send an email to test#testemail.com when the user submit a message in the form

PHP contact form

I've looked through a lot of pages to find an answer for my problem. But I can't figure out why my form isn't working.
I tried different versions of codes from premade examples but I can't get it to work.
This is my php above my form
<?php
$name = $_POST['name'];
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'me#email.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $email)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again!</p>';
}
}
?>
and this is my form
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" placeholder="Your Name">
<label>Email</label>
<input name="email" type="email" placeholder="Your Email">
<label>Subject</label>
<input name="subject" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" name="message" placeholder="Your Message"></textarea>
<input id="submit" name="submit" type="submit" value="Send">
</form>
I've only changed my email in this example here the rest is the same. I'm testing this live on a modern server with php 5+ support
Basicly everything works fine except that I don't get an email.
I can't find out how to make it work sadly. Any ideas would be cool :/
Edit: GOD DAMNIT IM A TOTAL IDIOT
Gmail Spam filter is strong in this one.
You have not defined $from.
That is why it is not sending mail.
Also, please check SMTP settings for your machine/server.
SMTP ports may not be configured, that is why mail is not sending.
Try this for the form:
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" type="text" placeholder="Your Name">
<label>Email</label>
<input name="email" type="text" placeholder="Your Email">
<label>Subject</label>
<input name="subject" type="text" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" type="text" name="message" placeholder="Your Message"></textarea>
<input id="submit" name="submit" type="submit" value="Send">
Also try following this working format:
<?php
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$txt,$headers);
?>
You could just replace the value inside the " " with the post function.
Edit ( This will surely work ):
if (isset($_POST['submit'])) {
if (mail ($to, $subject, $body, $email)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again!</p>';
}
}
The fourth Parameter for the Mail function is header. Where You can set Mail form and others (http://php.net/manual/en/function.mail.php ). Please set that, and also check the SMTP configuration as "Programming Student" told you.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'to#test.com';
$from = 'from#test.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail ($to, $subject, $body, $from)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again! </p>';
}
?>
You have missed to assign the $from variable
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" type="text" placeholder="Your Name">
<label>Email</label>
<input name="email" type="text" placeholder="Your Email">
<label>Subject</label>
<input name="subject" type="text" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" name="message" placeholder="Your Message"> </textarea>
<input id="submit" name="submit" type="submit" value="Send">
</form>
Make sure the php file name "contact.php"
Now My HTML goes this way -->
<body> Fields with * are mandatory.
<form action="mail.php" method="POST">
<fieldset>
<legend>Contact Information</legend>
<p>Name*</p> <input type="text" name="name">
<p>Email*</p> <input type="text" name="email">
</fieldset>
<br />
<br />
<fieldset>
<legend>Other Information</legend>
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Contact Us</option>
<option value="change">Information Change</option>
<option value="addition">Other</option>
</select>
<br />
</fieldset>
<br />
<fieldset>
<legend>Your Message</legend>
<p>Message*</p><textarea name="message" rows="8" cols="29"></textarea><br /><p>
<input type="submit" value="Send" class="but"> <input type="reset" value="Clear" class="but">
</fieldset>
</form>
</body>
and now the main thing that is PHP goes this way ->
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "youremail#domain.com";
$subject = "Contact Form";
$mailheader = "$name submited the form.";
if (filter_var("$email", FILTER_VALIDATE_EMAIL)) {
if ($email === "" || $message === "" || $name === "") {
echo "ERROR! Email and message and Name are Mandatory. <a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Back</a>";
}
else {
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($email, "Name of Form Here", "Your Form has been submitted. Your problem will be noticed soon. This is a no reply mail address. Please dont reply back. - WeBoosters India", "Thankyou") or die("Error!");
echo "Thank You!" . " -" . "<a href='index.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
}
else {
echo "The email is not valid. Please write a proper email address. - <a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Back</a>";
}
?>
Hope you like it! Best of luck.

PHP Contact Form that shows success and error Message on the same page

I have created a PHP contact form on my site which works well except to see the Success or Error message it sends users to a the thank-you.php page. That is how I have it set up but I want users to submit and the form should dissapear and say Thank You! in place of the form.
Here is my HTML for the form:
<form class="form-foot" action="thank-you.php" method="post">
<fieldset>
<legend>Footer contact form</legend>
<div class="field">
<label for="name">Your name: </label>
<input name="name" id="name" type="text" placeholder="Name" class="required field-name" required>
</div>
<div class="field">
<label for="email">Your email: </label>
<input name="email" id="email" type="email" placeholder="Email address" class="required field-email" required>
</div>
<div class="field">
<label for="message">Message: </label>
<textarea name="message" id="message" cols="30" rows="8" class="required field-message" placeholder="Your message" required></textarea>
</div>
<div class="field-submit">
<input class="sendbutton" type="submit"/>
</div>
</fieldset>
</form>
And here is my PHP in the thank-you.php page:
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "myemail#mysite.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
How can I make the form disappear on submission and echo the Thank You success message without going to thank-you.php or refreshing the page.
Thanks
Replace:
<form class="form-foot" action="thank-you.php" method="post">
with:
<form name="myform" class="form-foot" action="" method="post">
Give a name to your submit button:
<input name="submit" class="sendbutton" type="submit"/>
Move the code from thank-you.php to yourform.php:
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "myemail#mysite.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
}
you can use ajax to post data to the thank-you.php file, from javascript. by calling a function on submit instead of the action attribute in the form. the function can have the below format
var url = "thank-you.php";
var data = $('#your-form-id').serialize();
$.ajax({
type: "post",
url: url,
data: data,
success: function(msg) {
}
});
On getting the message from the thank-you page you can make use of it to assign it the html containing the form to replace the form with thank you!

cantact form php file doesn't work(Jquery Magical contact form - tutsgeek)

i have a form that work with jquery this form is :
download link for this is
http://www.4shared.com/rar/qkIP2Ulb/magical-contact-form.html
<form class="fcf-contact-form" action="mail.php" method="post">
<div class="right">
<input type="text" name="name" id="name" class="input">
<input type="text" name="email" id="email" class="input">
<div class="left">
<textarea name="message" cols="0" rows="5" class="textarea"></textarea>
<input type="submit" name="submit" value="Send message !" class="submit"/>
</div>
</div>
</form>
and mail.php file code is that code :
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n email: $email \n message: $message";
$recipient = "milad.esmailzade#yahoo.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "<a href='your page link here.php' style='text-decoration:none;color:#ff0099;'></a>";
?>
i upload this contact form on the host and when i click send i dont recieve email from this form !
what is the problem ?
You have to ask your hosting technical support why the PHP mail function does not work?
Try setting SMTP and user parameters, like this:
ini_set("SMTP","mail.mydomain.com" ); // or the IP
ini_set('sendmail_from', 'Me#mydomain.com'); // Account used to deliver the messages.

Categories