With purpose to save your time I have two screenshots of my contact form.
Also instead of expected result the message "Thank you. Your message has been received" I got in new window. How can I place the message in that input element? Where am I wrong?
You can check my contact form by this link just send any message.
Thank you so much for your time and answers.
<form action="contact/form-handler.php" method="post">
<fieldset>
<div class="form-row">
<div class="form-group col-md-6">
<input type="text" class="form-control" name="name" id="name" placeholder="Your Name"/>
</div>
<div class="form-group col-md-6">
<input type="text" class="form-control" name="email" id="email" placeholder="Your Email"/>
</div>
</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" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
</div>
<div>
<input type="hidden" name="hidden" value="" />
<div class="nocomment">
<label for="nocomment"></label>
<input id="nocomment" class="nocomment" value="" name="nocomment" />
</div>
<div class="text-center">
<input type="submit" value="Send Message" name="submit"/>
<input type="reset" value="Clear Message" name="reset"/>
</div>
</div>
<input type="hidden" name="v_error" id="v-error" value="Required" />
<input type="hidden" name="v_email" id="v-email" value="Enter a valid email" />
</fieldset>
</form>
And my contact/form-handler.php
<?php
include('SMTPClass.php');
$emailto = 'myemail.com';
// retrieve from parameters
$emailfrom = isset($_POST["email"]) ? $_POST["email"] : "";
$nocomment = isset($_POST["nocomment"]) ? $_POST["nocomment"] : "";
$subject = 'Email from InWebWorld';
$message = '';
$response = '';
$response_fail = 'There was an error verifying your details.';
// Honeypot captcha
if($nocomment == '') {
$params = $_POST;
foreach ( $params as $key=>$value ){
if(!($key == 'ip' || $key == 'emailsubject' || $key == 'url' || $key == 'emailto' || $key == 'nocomment' || $key == 'v_error' || $key == 'v_email')){
$key = ucwords(str_replace("-", " ", $key));
if ( gettype( $value ) == "array" ){
$message .= "$key: \n";
foreach ( $value as $two_dim_value )
$message .= "...$two_dim_value<br>";
}else {
$message .= $value != '' ? "$key: $value\n" : '';
}
}
}
$response = sendEmail($subject, $message, $emailto, $emailfrom);
} else {
$response = $response_fail;
}
echo $response;
// Run server-side validation
function sendEmail($subject, $content, $emailto, $emailfrom) {
$from = $emailfrom;
$response_sent = 'Thank you. Your messsage has been received.';
$response_error = 'Error. Please try again.';
$subject = filter($subject);
$url = "Origin Page: ".$_SERVER['HTTP_REFERER'];
$ip = "IP Address: ".$_SERVER["REMOTE_ADDR"];
$message = $content."\n$ip\r\n$url";
// Validate return email & inform admin
$emailto = filter($emailto);
// Setup final message
$body = wordwrap($message);
// Create header
$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
// Send email
$mail_sent = #mail($emailto, $subject, $body, $headers);
$response = $mail_sent ? $response_sent : $response_error;
return $response;
}
// Remove any un-safe values to prevent email injection
function filter($value) {
$pattern = array("/\n/", "/\r/", "/content-type:/i", "/to:/i", "/from:/i", "/cc:/i");
$value = preg_replace($pattern, "", $value);
return $value;
}
exit;
?>
If this php code is in contact/form-handler.php than instead of echo $response; you should redirect back to your contact page with the message, like header('Location: contact_page_url?message='.urlencode($response));And in your contact page put below your form:
<script>
function findGetParameter(parameterName) {
var result = null, tmp = [];
location.search.substr(1).split("&").forEach(function (item){
tmp = item.split("=");
if (tmp[0] === parameterName)
result = decodeURIComponent(tmp[1]);
});
return result;
}
document.querySelector('#nocomment').value = findGetParameter('message') || '';
</script>
Related
i am trying to create simple contact form with captcha in php. However it turns out implementing captcha is out of my league.
I found a simple answer on stackoverflow opn similar problem which pushed me 1 step closer to the end, but again i got stuck.
So i need a contact form that only check if text is entered and if correct captcha is answered, email is not mandatory.
</br>
<?php
$a=rand(2,9);
$b=rand(2,9);
$c=$a+$b;
if (isset($_POST['contact_text']) && isset($_POST['contact_email']) ) {
$contact_text = $_POST['contact_text'];
$contact_email = $_POST['contact_email'];
$recaptcha = $_POST['recaptcha'];
$info = 'Pranešimas apie korupciją: ';
$sender = 'Atsiuntė: ';
if (!empty($contact_text) && ($recaptcha == $c )) {
echo $recaptcha;
$to = 'muksinovas#gmail.com';
$subject = 'Korupcija';
$body = $sender."\n".$contact_email."\n".$info."\n".$contact_text;
$headers = 'From: '.$contact_email;
if (#mail($to,$subject, $body, $headers)) {
echo 'Jūsų pranešimas sėkmingai išsiustas. ';
} else {
} echo 'Įvyko klaida, bandykite dar karta.';
} else {
echo 'Neteisingai užpildyta forma.';
}
}
?>
<form action="contact1.php" method="post">
Pranešimas apie korupciją:<br><textarea name="contact_text" rows="6" cols="30" maxlength="1000" ></textarea><br><br> <!-- -->
Email (nebūtinas):<br><input type="text" name="contact_email" maxlength="30">
<?php echo $a."+".$b."="?><input type="number" name="recaptcha" maxlength="2" style="width:40px" />
<input type="submit" value="Siusti">
<br>
</form>
Now the problem is that I always get the message that details are incorrect. I tried to echo recaptcha just to see if $c is correct and it works. But for some reason not able to compare $recaptcha with $c or some other issue I am not sure.
The value of $c will be a completely different value when the user submits the contact form vs when your validation checks it. The value will change on every request because the script is re-interpreted.
You will have to save the value of $c on the initial page load, so that you can compare it afterwards in the next request. You can do that by storing it in $_SESSION.
You can write this
<?php
$min_number = 2;
$max_number = 9;
$random_number1 = mt_rand($min_number, $max_number);
$random_number2 = mt_rand($min_number, $max_number);
if (isset($_POST['contact_text']) && isset($_POST['contact_email']) ) {
$contact_text = $_POST['contact_text'];
$contact_email = $_POST['contact_email'];
$recaptcha = $_POST['recaptcha'];
$firstNumber = $_POST["firstNumber"];
$secondNumber = $_POST["secondNumber"];
$checkTotal = $firstNumber + $secondNumber;
$info = 'Pranešimas apie korupciją: ';
$sender = 'Atsiuntė: ';
if (!empty($contact_text) && ($recaptcha != $checkTotal )) {
echo $recaptcha;
$to = 'muksinovas#gmail.com';
$subject = 'Korupcija';
$body = $sender."\n".$contact_email."\n".$info."\n".$contact_text;
$headers = 'From: '.$contact_email;
if (#mail($to,$subject, $body, $headers)) {
echo 'Jūsų pranešimas sėkmingai išsiustas. ';
} else {
} echo 'Įvyko klaida, bandykite dar karta.';
} else {
echo 'Neteisingai užpildyta forma.';
}
}
?>
<form action="contact1.php" method="post">
Pranešimas apie korupciją:<br><textarea name="contact_text" rows="6" cols="30" maxlength="1000" ></textarea><br><br> <!-- -->
Email (nebūtinas):<br><input type="text" name="contact_email" maxlength="30">
<?php
echo $random_number1 . ' + ' . $random_number2 . ' = ';
?>
<input type="number" name="recaptcha" maxlength="2" style="width:40px" />
<input name="firstNumber" type="hidden" value="<?php echo $random_number1; ?>" />
<input name="secondNumber" type="hidden" value="<?php echo $random_number2; ?>" />
<input type="submit" value="Siusti">
<br>
</form>
This might solve your problem
you should to use session to solve your problem, i did little changes in your code, it should to work perfectly.
<?php
#session_start();
if (isset($_POST['contact_text']) && isset($_POST['contact_email']) ) {
$contact_text = $_POST['contact_text'];
$contact_email = $_POST['contact_email'];
$recaptcha = $_POST['recaptcha'];
$info = 'Pranešimas apie korupciją: ';
$sender = 'Atsiuntė: ';
if (!empty($contact_text) && ($recaptcha == $_SESSION["captcha"])) {
echo $recaptcha;
$to = 'muksinovas#gmail.com';
$subject = 'Korupcija';
$body = $sender."\n".$contact_email."\n".$info."\n".$contact_text;
$headers = 'From: '.$contact_email;
if (#mail($to,$subject, $body, $headers)) {
echo 'Jūsų pranešimas sėkmingai išsiustas. ';
} else {
} echo 'Įvyko klaida, bandykite dar karta.';
}else{
echo 'Neteisingai užpildyta forma.';
}
}else{
$a=rand(2,9);
$b=rand(2,9);
$c=$a+$b;
//setting captcha code in session
$_SESSION["captcha"] = $c;
?>
<form action="contact1.php" method="post">
Pranešimas apie korupciją:<br><textarea name="contact_text" rows="6" cols="30" maxlength="1000" ></textarea><br><br> <!-- -->
Email (nebūtinas):<br><input type="text" name="contact_email" maxlength="30">
<?php echo $a."+".$b."="?><input type="number" name="recaptcha" maxlength="2" style="width:40px" />
<input type="submit" value="Siusti">
<br>
</form>
<?php
}
?>
As my discussion title says. Form works fine when submitting all corresponding info, but does not send "Comments" section. Any help would be greatly appreciated.
Here is my Form Code:
<form role="form" id="footerform" name="footform" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<div class="form-group"> <span id="footformerror" class="error"></span>
<input name="footname" id="footname" class="form-control input-sm" placeholder="First Last" pattern="[A-Za-z]+ [A-Za-z]+" value="<?php if (isset($footname)) { echo $footname;} ?>" />
<?php if (isset($err_footname)) { echo $err_footname;}?>
<?php if (isset($err_footpatternmatch)) { echo $err_footpatternmatch;}?>
</div>
<div class="form-group">
<input type="email" name="footemail" class="form-control input-sm" id="footemail" autocomplete="off" required pattern="^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+#([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$" placeholder="example#email.com" value="<?php if (isset($footemail)) { echo $footemail;} ?>" />
</div>
<div class="form-group">
<textarea type="text" name="footcomments" id="footcomments" class="form-control input-sm" rows="6" placeholder="Comments" required></textarea>
<?php if (isset($footcomments)) { echo $footcomments; } ?>
</div>
<button type="submit" name="footsend" class="btn btn-default btn-xs" >Submit</button>
<input type="reset" value="Reset!" class="btn btn-default btn-xs">
</form>
Here is my PHP Coding:
if(isset($_POST['footsend'])) {
if (isset($_POST['footname'])) { $footname = $_POST['footname']; } else { $footname = '';}
if (isset($_POST['footemail'])) { $footemail = $_POST['footemail']; }else { $footemail = '';}
if (isset($_POST['footcomments'])) {$footcomments = filter_var($_POST['footcomments'], FILTER_SANITIZE_STRING );
}
if (isset($_POST['ajaxrequest'])) { $ajaxrequest = $_POST['ajaxrequest']; } else { $footcomments = '';}
$footformerrors = false;
if ($footname === '') :
$err_footname = '<div class="error">Sorry, your name is a required field</div>';
endif; // input field empty
if ( !(preg_match('/[A-Za-z]+ [A-Za-z]+/', $footname)) ) :
$err_footpatternmatch = '<div class="error">Sorry, the name must be in the format: First Last</div>';
endif; // pattern doesn't match
if ( !(preg_match('/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+#([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/', $footemail)) ) :
$err_footemail = '<div class="error">Sorry, enter valid email address</div>';
endif; // pattern doesn't match
if (strlen($footcomments) < 2) :
$err_footcomments = '<div class="error">Please enter you comment.</div>';
endif; // input field empty
error_reporting(E_ERROR | E_PARSE);
$footemail_to = 'example#email.com';
$footemail_subject = 'Website Footer Comment Submission';
$footemail_from = $footemail;
$footemail_contact = $footname;
$footemail_message = "Email submission from ".$footname." at scdesignprint.net footer comments section.\n\n";
function clean_string($string) {
$bad = array('content-type','bcc:','to:','cc:','href');
return str_replace($bad,"",$string);
}
$footemail_message .= "Name: ".clean_string($footname)."\n";
$footemail_message .= "Email: ".clean_string($footemail)."\n";
$footemail_message .= "Comments: ".clean_string($footcomments)."\n";
$footheaders = "From: ".$footemail_from."\r\n".
"Reply-To: ".$footemail_contact."\r\n" ;
mail($footemail_to, $footemail_subject, $footemail_message, $footheaders);
This line is clearing your comments :
if (isset($_POST['ajaxrequest'])) { $ajaxrequest = $_POST['ajaxrequest']; } else { $footcomments = '';}
This is a contact from using HTML5 and PHP. Works well for me
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'contact#tangledindesign.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '4') {
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>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
I have an issue with a contact form I have set up on a clients site, the form posts to my email address no problem but doesn't for my client who's domain is registered through 123 reg and email accounts are set up within Gmail. On contacting my web host they have suggested using SMTP, this is something I have never used before, I have googled this but haven't came to any light. Anyone have any ideas?
Thanks,
Melissa
<?php
if (array_key_exists('submit', $_POST)) {
$to = 'hello#email.co.uk'; //change this to suit your admin email address
$subject = 'Website enquiry'; //change this to the mail subject you want the admin to receive
$expected = array('name', 'email', 'tel', 'message1'); //list all of the fields in the form
$required = array('name', 'email', 'message1'); //list the required fields in the form
$missing = array();
$suspect = false;
$pattern = '/Content-Type:|Bcc:|Cc:/i';
function isSuspect($val, $pattern, &$suspect) {
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}
else {
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
}
isSuspect($_POST, $pattern, $suspect);
if ($suspect) {
$mailSent = false;
unset($missing);
}
else {
foreach ($_POST as $key => $value) {
$temp = is_array($value) ? $value : trim($value);
if (empty($temp) && in_array($key, $required)) {
array_push($missing, $key);
}
elseif (in_array($key, $expected)) {
${$key} = $temp;
}
}
}
if (!empty($email)) {
$checkEmail = '/^[^#]+#[^\s\r\n\'";,#%]+$/';
if (!preg_match($checkEmail, $email)) {
array_push($missing, 'email');
}
}
if (!$suspect && empty($missing)) {
$message .= "Name: $name\n\n";
$message .= "Email address: $email\n\n";
$message .= "Telephone number: $tel\n\n";
$message .= "Message: $message1\n\n";
$message = wordwrap($message, 70);
$additionalHeaders = "From: $email";
$complete = mail($to, $subject, $message, $additionalHeaders);
if ($complete) {
unset($missing);
}
}
}
?>
Below shows the form:
<?php
if ($_POST && isset($missing)) {
echo'<p class="warning">Please complete the missing or incorrect fields.</p>';
}
if ($_POST && isset($complete)) {
echo '<p class="green"><strong>Thank you for contacting us. We will be in touch soon.</strong></p>';
}
else{?>
<form method="post" action="" id="contact_form" class="validate">
<fieldset>
<legend>Your Details</legend>
<label for="name"><b>Full Name</b></label>
<input name="name" placeholder="John Smith" class="" <?php if (isset($missing)) {echo 'value="'.htmlentities($_POST['name']).'"';} ?> />
<br>
<label for="email"><b>Email Address</b></label>
<input type="email" name="email" placeholder="hello#shnuggle.com" class="" <?php if (isset($missing)) {echo 'value="'.htmlentities($_POST['email']).'"';} ?> />
<br>
<label for="phone"><b>Phone Number <span class="note">(optional)</span></b></label>
<input type="tel" name="tel" placeholder="+44 (0)28 9012 3456" class="" <?php if (isset($missing)) {echo 'value="'.htmlentities($_POST['tel']).'"';} ?> />
<br>
<legend>Your Message</legend>
<textarea name="message1" <?php if (isset($missing)) {echo 'value="'.htmlentities($_POST['message1']).'"';} ?> />Hello,</textarea>
</fieldset>
<!--<button type="submit" class="btn submit"><span class="icon">m</span> Send Message</button>-->
<input type="submit" class="btn" name="submit" value="Send Message" />
<button type="reset" class="btn reset">Clear form</button>
</form>
<?php }?>
It's Work !!
If you got Error undefined Variable on 54 line
than convert
$message .= "Name: $name\n\n";
to
$message = "Name: $name\n\n";
I'm using a contact form for my website, which I validate and then email to myself, the validation is working correctly and it emails me if the user enters all the details correctly first time. However if the user enters incorrect data, then corrects it and hits send again, it won't send an email, below is the form and PHP code I have so far.
HTML code for contact form
<form action="contact.php" method="post">
<fieldset>
<label for="name">Name:<span class="star">*</span></label> <br />
<input type="text" name="name" id="name" placeholder="Enter your name" maxlength="50" required />
<label for="email">Email:<span class="star">*</span></label> <br />
<input type="email" name="email" id="email" placeholder="Enter your email address" maxlength="100" required />
<label for="number">Telephone: </label><input type="tel" name="number" id="number" placeholder="Enter your phone number" maxlength="12" />
<label for="message">Message:<span class="star">*</span></label>
<textarea name="message" id="message" placeholder="Enter your message" cols="54" rows="5" required></textarea>
<p class="small"><span class="star">*</span> Denotes a required field </p>
<input type="submit" id="send" name="send" value="Send" />
</fieldset>
</form>
PHP code for sending the form
function fix_string($var)
{
if(get_magic_quotes_gpc()) $var = stripslashes($var);
$var = strip_tags($var);
return $var;
}
{
$details = array('name' => fix_string($_POST['name']),
'email' => fix_string($_POST['email']),
'number' => fix_string($_POST['number']),
'message' => fix_string($_POST['message']));
}
$send = $_POST['send'];
$message = "";
foreach ($details as $field => $detail)
$message .= $field . ": " . $detail . "<br />";
$to = "smokey.12345#hotmail.co.uk";
$subject = "Website contact form";
$message = wordwrap($message, 70, "/r/n");
$headers = "From ". $details['email'];
function trim_value(&$value)
{
$value = trim($value);
}
array_walk($details, 'trim_value');
if ($send)
{
foreach ($details as $field => $detail)
{
if (empty($detail) && $field!='number')
echo "<p class='error'>Please fill in the required field: " . ucfirst($field) . "<br /></p>";
}
}
else
{
mail($to, $subject, $message, $headers);
echo "<p class='success'>Mail was sent successfully</p>";
}
EDIT
In order for the code to work on the same page, you need to set the action to action=""
Otherwise, you need to use two pages. One for your form and one for contact.php which is your handler. I suggest you use two pages, but here is a version that will work inside one page.
<?php
if(isset($_POST['send'])) {
function fix_string($var)
{
if(get_magic_quotes_gpc()) $var = stripslashes($var);
$var = strip_tags($var);
return $var;
}
$details = array('name' => fix_string($_POST['name']),
'email' => fix_string($_POST['email']),
'number' => fix_string($_POST['number']),
'message' => fix_string($_POST['message']));
function trim_value(&$value)
{
$value = trim($value);
}
array_walk($details, 'trim_value');
foreach ($details as $field => $detail)
{
if (empty($detail) && $field!='number')
die("<p class='error'>Please fill in the required field: " . ucfirst($field) . "<br /></p>");
}
$message = "";
foreach ($details as $field => $detail)
$message .= $field . ": " . $detail . "\n";
$send = $_POST['send'];
$email = $_POST['email'];
$to = "smokey.12345#hotmail.co.uk";
$subject = "Website contact form";
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
echo "<p class='success'>Mail was sent successfully</p>";
exit;
} // closing brace for if(isset($_POST['send'])) {
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="" method="post">
<fieldset>
<label for="name">Name:<span class="star">*</span></label> <br />
<input type="text" name="name" id="name" placeholder="Enter your name" maxlength="50" />
<label for="email">Email:<span class="star">*</span></label> <br />
<input type="email" name="email" id="email" placeholder="Enter your email address" maxlength="100" />
<label for="number">Telephone: </label><input type="tel" name="number" id="number" placeholder="Enter your phone number" maxlength="12" />
<label for="message">Message:<span class="star">*</span></label>
<textarea name="message" id="message" placeholder="Enter your message" cols="54" rows="5" ></textarea>
<p class="small"><span class="star">*</span> Denotes a required field </p>
<input type="submit" id="send" name="send" value="Send" />
</fieldset>
</form>
</body>
</html>
Original answer
This line is not properly formatted.
$message = wordwrap($message, 70, "/r/n");
change it to:
$message = wordwrap($message, 70, "\r\n");
You need to use \ instead of /
EDIT
The only way I could get your form to work, is to add a die function.
Try this now:
<?php
function fix_string($var)
{
if(get_magic_quotes_gpc()) $var = stripslashes($var);
$var = strip_tags($var);
return $var;
}
$details = array('name' => fix_string($_POST['name']),
'email' => fix_string($_POST['email']),
'number' => fix_string($_POST['number']),
'message' => fix_string($_POST['message']));
function trim_value(&$value)
{
$value = trim($value);
}
array_walk($details, 'trim_value');
foreach ($details as $field => $detail)
{
if (empty($detail) && $field!='number')
die("<p class='error'>Please fill in the required field: " . ucfirst($field) . "<br /></p>");
}
$message = "";
foreach ($details as $field => $detail)
$message .= $field . ": " . $detail . "\n";
$send = $_POST['send'];
$email = $_POST['email'];
$to = "smokey.12345#hotmail.co.uk";
$subject = "Website contact form";
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
echo "<p class='success'>Mail was sent successfully</p>";
exit;
?>
I have a simple contact me script, which fires an email on submit.
The email is sent, but there are no form values in the email (name: empty, ...).
Why doesn't my contact script work?
<?php
if ($action == "send") //isset wyslij
{
if (!$_POST[name] || !$_POST[email] || !$_POST[phone] || !$_POST[enquiry])
{
$problem = TRUE;
echo("<p>You have to fill all form.</p>");
}
if (! $problem)
{
$data = date("d.m.y");
$message = "
<p>Name: $_POST[name]</p>
<p>Phone: $_POST[phone]</p>
<p>Email: $_POST[email]</p>
<br>
<p>Enquiry: $_POST[enquiry]</p>";
$od = "contactmail#asdasdas.com";
$content = $message;
$header = "From: $od \r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
(mail('email#example.com', 'New message from website', $content, $header));
echo("<br><p>Message has been sent.</p>");
}
else
{
echo("<p>Try <a href=contact.php>again</a></p>");
}
}
?>
<form action="contact.php?action=send" method="post" enctype="text/plain">
<label for="name">Name</label><input type="text" name="name" /></br></br>
<label for="email">Email</label><input type="text" name="email" /></br></br>
<label for="phone">Phone</label><input type="text" name="phone" /></br></br>
<label for="enquiry">Enquiry</label><textarea name="enquiry" cols="20" rows="10"></textarea></br></br>
<input type="submit" id="contact_button" value="Send" />
</form>
Valid values for enctype in tag are:
application/x-www-form-urlencoded
multipart/form-data
you have text/plain and thats why it's not working.
simply remove the "enctype" argument from the HTML form code and try again?