The HTML code is this
<form class="rnd5" action="mail.php" method="post">
<div class="form-input clear">
<label for="name">Nume <span class="required">*</span><br>
<input type="text" name="name" id="name" value="" size="22">
</label>
<label for="email">Email <span class="required">*</span><br>
<input type="text" name="email" id="email" value="" size="22">
</label>
</div>
<div class="form-message">
<textarea name="message" id="message" cols="25" rows="10"></textarea>
</div>
<p>
<input type="submit" value="Submit" class="button small orange">
<input type="reset" value="Reset" class="button small grey">
</p>
</form>
And the php code is this one :
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "pascal.m.cornel#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
But it doesnt work.... i don't know what to do , i need some help here please.
If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.
Source: http://php.net/manual/en/function.mail.php
In your case, neither \r\n nor \n is needed as you're only using a single extra header.
Related
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>
When the submit button is clicked, the browser goes to www.****.com/contact.php and the page is blank. The email is also not delivered. This is my first time dealing with php. What am I missing?
Here is the form:
<form class="comment-form" action="contact.php" method="POST">
<p class="comment-notes">Your email address will not be published. All fields are required.</p>
<p class="comment-form-email">
<label for="author">Name</label>
<span class="required">*</span>
<input id="author" type="text" class="input-text" name="name">
</p>
<p class="comment-form-author">
<label for="email">Email</label>
<span class="required">*</span>
<input id="email" type="text" class="input-text" name="email">
</p>
<p class="comment-form-url">
<label for="subject">Subject</label>
<span class="required">*</span>
<input id="subject" type="text" class="input-text" name="subject">
</p>
<p class="comment-form-comment">
<label for="message">Message</label>
<textarea name="message" id="message" cols="45" rows="10" class="input-text"></textarea>
</p>
<p class="form-submit">
<input class="btn btn-md btn-default" name="submit" type="submit" id="button" value="Send"><input type="reset" value="Clear">
</p>
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$formcontent = "From: $name\n Message: $message";
$recipient = "me#example.com";
$subject = "$subject";
$mailheader = "From: $email \r\n";
error_reporting(E_ALL);
ini_set(display_errors, 1);
mail($recipient, $subject, $formcontent, $mailheader) or die ("Error!");
echo "Thank You! We will respond to your inquiry as soon as possible"; " -"<a href='contact.html' style='text-decoration:none;color:#ff0099;'> "Return Home"</a>;
?>
It looks like this form is posting to itself? IF that's the case, I think you should probably be using
<form class="comment-form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
htmlspecialchars() is a safety thing. Helps to prevent against some hacks.
Looks like your PHP isn't being called properly because it isn't being triggered by the submit button. The code below executes when the submit button is pressed.
if(isset($_POST['submit']
{
// put your PHP code here, this executes when submit is...submitted
}
Give this a shot, it should help you out some.
<?php
error_reporting(E_ALL);
ini_set(display_errors, 1);
if(isset($_POST['submit']))
{
//Gather the POST info and set them to variables
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Setup the message and define who will be emailed the info
$formcontent = "From: $name\n Message: $message";
$recipient = "pbentley07#gmail.com";
$headers = 'From:' . $email;
mail("$recipient", $subject, $formcontent, $headers) or die ("Error!");
echo "Thank You! We will respond to your inquiry as soon as possible! - <a href='contact.html' style='text-decoration:none;color:#ff0099;'>Return Home</a>";
}
?>
<form class="comment-form" action="contact.php" method="POST">
<p class="comment-notes">Your email address will not be published. All fields are required.</p>
<p class="comment-form-email">
<label for="author">Name</label>
<span class="required">*</span>
<input id="author" type="text" class="input-text" name="name">
</p>
<p class="comment-form-author">
<label for="email">Email</label>
<span class="required">*</span>
<input id="email" type="text" class="input-text" name="email">
</p>
<p class="comment-form-url">
<label for="subject">Subject</label>
<span class="required">*</span>
<input id="subject" type="text" class="input-text" name="subject">
</p>
<p class="comment-form-comment">
<label for="message">Message</label>
<textarea name="message" id="message" cols="45" rows="10" class="input-text"></textarea>
</p>
<p class="form-submit">
<input class="btn btn-md btn-default" name="submit" type="submit" id="button" value="Send"><input type="reset" value="Clear">
</p>
</form>
in your echo statement, you have bad syntax. Try
echo "Thank You! We will respond to your inquiry as soon as possible - <a href='contact.html' style='text-decoration:none;color:#ff0099;'>\"Return Home\"</a>";
Could you confirm that the page+code you posted here
is contact.php file?
Try to fix your php code first, this line:
echo "Thank You! We will respond to your inquiry as soon as possible"; " -"<a href='contact.html' style='text-decoration:none;color:#ff0099;'> "Return Home"</a>;
must be:
echo "Thank You! We will respond to your inquiry as soon as possible";
?>
Return Home
<?php
You have some serious "errors" in your PHP:
$message is not defined
$subject is not defined
It's ini_set('display_errors', 1);, not ini_set(display_errors, 1);
Your echo line is invalid, remove the additional HTML part
Your final code should looke like this:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$formcontent = "From: $name\n Message: $message";
$recipient = "me#example.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die ("Error!");
echo "Thank You! We will respond to your inquiry as soon as possible";
?>
<a href='contact.html' style='text-decoration:none;color:#ff0099;'> "Return Home"</a>
You might also want to read up on form validation
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.
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
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.