I want to do a "Contact Me" page. I have a problem as I am not receiving the email for testing. First, I used a localhost from my terminal with the following command:
php -S 127.0.0.1:8080
When I access the localhost:8080 the website works fine, but I am not receiving any emails from the contact me. Here is my HTML & php
HTML:
<form class="contact-form" action="contactform.php" method="post">
<input type="text" name="name" class="form-control" placeholder="Name" required><br>
<input type="email" name="email" class="form-control" placeholder="Email" required><br>
<textarea name="message" class="form-control" rows="4" placeholder="Message" required></textarea><br>
<button type="submit" name="submit" class="form-control submit">SEND MESSAGE</button>
</form>
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$msg = $_POST['message'];
$mailTo = "monbay#inboxbear.com";
$subject = "Form Submission from ".$name;
mail($mailTo, $subject, $msg);
echo '<p>Your message has been sent!</p>';
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
CSS y PHP of my contact-form.
The page works perfectly but I'm trying to send an email and the button of send doesn't work. In the image you can see that when I try to send an email the button stays white. At the same time the button Clear works perfect! I attach my code
CONTACT.HTML
<form action="mail.php" method="POST" class="contact-form">
<input type="text" name="name" placeholder="Name" class="required">
<input type="email" name="email" placeholder="Email address" class="contact-form-email required">
<input type="text" name="subject" placeholder="Subject" class="contact-form-subject">
<textarea name="message" placeholder="Message" class="required" rows="7"></textarea>
<div class="response-message"></div>
<button class="border-button" type="reset" id="reset" name="reset">Limpiar</button>
<button class="border-button" type="submit" id="submit" name="submit">Enviar</button>
MAIL.PHP
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "sa*********#*******.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
mail function doesn't work on local server and also you need to set SMTP configuration in PHP to send mail.
Are you placing your form inside the form tag?
<form action="mail.php" method="post">
<input type="text" name="name" placeholder="Name" class="required">
<input type="email" name="email" placeholder="Email address" class="contact-form-email required">
<input type="text" name="subject" placeholder="Subject" class="contact-form-subject">
<textarea name="message" placeholder="Message" class="required" rows="7"></textarea>
<div class="response-message"></div>
<button class="border-button" type="reset" id="reset" name="reset">Limpiar</button>
<button class="border-button" type="submit" id="submit" name="submit">Enviar</button>
</form>
Hi guys i'm having a issue i hope you guys can help with, i'm typing in all the fields and then upon pressing submit i'm getting just "Error!" on my screen.
Please see the code:
HTML
<h2 class="formhead">Contact Form</h2>
<br>
<form class="form" action="mail.php" method="POST">
<p class="name">
<input type="text" name="name" id="name" placeholder="John Doe" />
<label for="name">Name</label>
</p>
<br>
<p class="email">
<input type="text" name="email" id="email" placeholder="mail#example.com" />
<label for="email">Email</label>
</p>
<br>
<p class="number">
<input type="text" name="number" id="number" placeholder="0774XXXXXXX" />
<label for="name">Contact Number</label>
</p>
<br>
<p class="web">
<input type="text" name="web" id="web" placeholder="www.example.co.uk" />
<label for="name">Website</label>
</p>
<br>
<p class="message">
<textarea name="message" id="message" placeholder="Write something to us" /> </textarea>
</p>
<br>
<p class="submit">
<input type="submit" value="Send"/>
</p>
</form>
PHP
<?php $name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$website = $_POST['web'];
$formcontent="From: $name \n Contact: $number \n Website: $web \n Message: $message";
$recipient = "enquiries#c(hidden)y.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email ";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
Any help would be much appreciated!
Thanks
Sam
Your script always reporting 'Error!' because the mail() function always fails. That's because some index you're using in the php file doesn't match to the input names in your form:
Change these:
$website = $_POST['website'];
to:
$website = $_POST['web'];
Or change it in your form.
Also you have to specify a name for the message textarea:
<textarea name="message" id="message" placeholder="Write something to us" />
This may fail again if it can't connect to mailserver. This is probably you're case if The SMTP is Disabled.
As per my comment, here's an example of a better die statement:
<?
$your_function or die("Error! a") // Just replace the letter a with anything. It serves as a simple link to your function that only you know. so you can go back and check it
This question already has answers here:
How to upload & Save Files with Desired name
(9 answers)
Closed 9 years ago.
I have form that allows users to send me a message on my email, but I want it that when a user fills the form and chooses a file the file gets uploaded to the server and the message gets sent to me. I did do the message part but I couldn't get the file uploaded. here is my code:
Index page:
<form action="mail.php" method="post" enctype='multipart/form-data'>
<input type="text" class="feedback-input" id="firstname" name="firstname" placeholder="First Name" size="30" required="">
<br/>
<input type="text" class="feedback-input" id="lastname" name="lastname" placeholder="Last Name" size="30" required="">
<br/>
<input type="email" class="feedback-input" id="title" name="title" placeholder="E-mail" size="30" required="">
<br/>
<textarea name="message" class="feedback-input" placeholder="What can I help you with?" style="height: 150px;" required=""></textarea><br/>
<br/>
<input type="file" name="file" id="file" placeholder=" " tabindex="1" required/><br/>
<input type="submit" name="submit" id="Submit" value="Send">
and this is the mail.php file:
<?php
$firstname = $_POST['firstname'];
$title = $_POST['title'];
$lastname = $_POST['lastname'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$formcontent=" From: $firstname $lastname \n Email Address: $title \n IP: $ip \n\n Description : $message";
$recipient = "myemail#yahoo.com";
$subject = "New Message!!";
$mailheader = "From: $title \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: www.mythankyoupage.com");
die();
?>
I think your file upload should be based on this
http://www.w3schools.com/php/php_file_upload.asp
Please comment if you get stuck somewhere and I'll gladly help! :)
EDIT: Apparently I have to pay to register another domain on their site to have email capabilities. Sorry for the wasted time, and thanks for the code fixes.
I don't have any experience with php. I am just starting to figure it out. I am trying to get my form to send the entered information to my email. I set an else tag but that is all that happens. If you see any errors please let me know. I really want this to work. See for yourself: Website The codes are:
HTML:
<form action="post_comment.php" method="post" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="comment" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
<input id="send" name="send" type="hidden" value="1" />
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['comment'];
$from = 'From: '. $email;
$to = 'powersjesse#yahoo.com';
$subject = 'WEBSITE';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['send'] == "1") {
if (mail($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}}
?>
I get Something went wrong, go back and try again! when I'm trying to submit the form.
Updated code.
<form action="post_comment.php" method="post" id="commentform">
rather than method="request"
edited to add
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1
edited (in response to edited question code...) to add http://php.net/manual/en/function.mail.php
your mail() parameters are in the wrong order; should be $to, $subject, $message [, $additional_headers, etc.]
According to your code:
if ($_REQUEST['submit']) {
if (mail($to, $subject, $body, $from))
{
echo '<p>Your message has been sent!</p>';
}
else
{
echo '<p>Something went wrong, go back and try again!</p>';
}
}
Getting the output of:
Something went wrong, go back and try again!
Means that something went wrong with the mail() function, it returned false , otherwise we would see the Your message has been sent! message.
The problem with the mail() function is that it doesn't show any errors or warning , it just returns false.
How to locate the problem?
Try writing something like:
if(mail("your.working.email#gmail.com" , "A subject for example" , "the content of this email","From: no-reply#yourdomain.com"))
echo "We are good";
else
echo "Something not workin";
If it works , check out the value of any of your posted variables right after declaring them.
echo $name;
echo $email;
echo $message;
Make sure that those variables are not empty and that the $email variable contains a legal and validated email address.
If the basic mail usage didn't work - it's something related to your php settings (php.ini) or a limitation by your server (contact your hosting company).
EDIT1: About your html form , the type attribute of the input fields should be text and not name or email.
Instead of <input type="email"...
Write <input type="text"...
<form action="post_comment.php" method="get" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="comment" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
</form>
method must be get/post
Your field "submit" is a HTML button to submit the form and will not be added to the form. Add another input field which is not visible:
<input id="send" name="send" type="hidden" value="1" />
and access the field in PHP with:
if ($_REQUEST['send'] == "1") {
I hope this helps you.
the name of the textarea is comment and you're using it as message in this line,
$message = $_REQUEST['message'];
Needs to be,
$message = $_REQUEST['comment'];
Also, the method of the form submission, needs to be POST like this,
<form action="post_comment.php" method="post" id="commentform">
please change form as follows
<form action="post_comment.php" method="post" id="commentform">
In the form you can use only get/post
Try this
<form action="post_comment.php" method="post" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="comment" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
and in your post page..
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: '. $email;
$to = 'powersjesse#yahoo.com';
$subject = 'WEBSITE';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
$headers = "From: $from \r\n";
//$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
}
-> Use POST instead of REQUEST
-> comment chaged to message
HTML
<form action="post_comment.php" method="post" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="message" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: '. $email;
$to = 'powersjesse#yahoo.com';
$subject = 'WEBSITE';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}}
?>