below is the php code for my contact form, the website is live at the moment and when i use the form to send a query using the contact us form, not all information gets through:
In the email that i receive, the only information that comes through is $subject and the message ($name would like to move in on $move.\r\n\n";). No other data that the client inputs on the website is listed in the email. I have looked at the code and cant seem to find what is wrong.
I would appreciate any help.
<?php
if(!$_POST) exit;
$to = 'mydomain#email.com';
$name = $_POST['txtname'];
$email = $_POST['txtemail'];
$phone = $_POST['txtphone'];
$comp = $_POST['txtcomp'];
$emp = $_POST['txtemp'];
$move = $_POST['txtmove'];
$comment = $_POST['txtmessage'];
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$subject = 'You\'ve been contacted by ' . $name . '.';
$msg = "You have been contacted by $name.\r\n\n";
$msg .= "$comment\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg = "You can call $name on $phone.\r\n\n";
$msg = "$name has $emp employees and the company name is $comp.\r\n\n";
$msg = "$name would like to move in on $move.\r\n\n";
$msg .= "-------------------------------------------------------------------------------------------\r\n";
if(#mail($to, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{
echo "<span class='success-msg'>Thanks for Contacting Us, We will call back to you soon.</span>";
}
else
{
echo "<span class='error-msg'>Sorry your message was not sent, Please try again.</span>";
}
?>
Thanks for the replies and suggestions, below is the HTML for the form:
<div id="map"></div>
<div class="dt-sc-margin50"></div>
<div class="container">
<div class="column dt-sc-three-fourth first">
<div class="hr-title">
<h3>Request A Call Back</h3>
<div class="title-sep">
</div>
</div>
<form method="post" class="dt-sc-contact-form" action="php/send.php" name="frmcontact">
<div class="column dt-sc-one-third first">
<p> <span class="auto-style2">Your Name</span><span> <input type="text" placeholder="Name*" name="txtname" maxlength="25" value="" required /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">Your Email Address<span> <input type="email" placeholder="Email*" name="txtemail" value="" required /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">Your Contact Number <span> <input type="text" placeholder="Phone" name="txtphone" value="" /> </span> </p>
</div>
<div class="column dt-sc-one-third first">
<p><span class="auto-style2">Company Name <span> <input type="text" placeholder="Company Name" name="txtcomp" value="" /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">No Of Employees <span> <input type="number" placeholder="No Of Employees" name="txtemp" value="" /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">Move In Date <span> <input type="date" placeholder="Move In Date" name="txtmove" value="" /> </span> </p>
</div>
<p> <span class="auto-style2">Please describe below what kind of office you are looking for,we will reply to your query on the same day.<textarea placeholder="Message*" name="txtmessage" maxlength "750" required ></textarea> </p>
<p> <input type="submit" value="Send Message" name="submit" /> </p>
</form>
<div id="ajax_contact_msg"></div>
</div>
Update 01/10/15
Hi Guys
I made the changes suggested by Dp and sebastianbrosch. The website is now live again but when i attempt to send the form, it says "the page save failed". Below is the updated php code, the html contact us page file remains the same.
Hi apologies i have pasted the php code, but for some reason, it is not showing up in the post. I will try again.
<?php
if(!$_POST) exit;
$to = 'mydomain#email.com';
$name = $_POST['txtname'];
$email = $_POST['txtemail'];
$phone = $_POST['txtphone'];
$comp = $_POST['txtcomp'];
$emp = $_POST['txtemp'];
$move = $_POST['txtmove'];
$comment = $_POST['txtmessage'];
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$subject = 'Office enquiry via domain.com from ' . $name . '.';
$msg = "You have been contacted by ".$name."\r\n\n";
$msg .= "You can contact ".$name." via email, ".$email.".\r\n\n";
$msg .= "You can call ".$name." on ".$phone.".\r\n\n";
$msg .= "$name has ".$emp." employees and the company name is ."$comp.".\r\n\n";
$msg .= $name." would like to move in on ."$move.".\r\n\n";
$msg .= $comment."\r\n\n";
$msg .= "---------------------------------------------------------------\r\n";
if(#mail($to, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{
echo "<span class='success-msg'>Thanks for Contacting Us, We have received your query and will be in touch soon.</span>";
}
else
{
echo "<span class='error-msg'>Sorry your message was not sent, Please try again or contact us via live chat.</span>";
}
?>
There are missing the points in front of the = in the following lines
$msg = "You can call $name on $phone.\r\n\n";
$msg = "$name has $emp employees and the company name is $comp.\r\n\n";
$msg = "$name would like to move in on $move.\r\n\n";
Replace with the following lines
$msg .= "You can call $name on $phone.\r\n\n";
$msg .= "$name has $emp employees and the company name is $comp.\r\n\n";
$msg .= "$name would like to move in on $move.\r\n\n";
Your Code :
$msg = "You have been contacted by $name.\r\n\n";
$msg .= "$comment\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg = "You can call $name on $phone.\r\n\n";
$msg = "$name has $emp employees and the company name is $comp.\r\n\n";
$msg = "$name would like to move in on $move.\r\n\n";
Try The Following :
$msg = "You have been contacted by ".$name."\r\n\n";
$msg .= $comment."\r\n\n";
$msg .= "You can contact ".$name." via email, ".$email.".\r\n\n";
$msg .= "You can call ".$name." on ".$phone.".\r\n\n";
$msg .= "$name has ".$emp." employees and the company name is $comp.".\r\n\n";
$msg .= $name." would like to move in on ."$move.".\r\n\n";
I think you had several string concatenation errors according to what you have explained in your question.
Related
This question already has answers here:
PHP mail does not get sent, how do I debug? [duplicate]
(2 answers)
Closed 4 months ago.
So this contact form used to work, however now it loads and says mail sent when someone clicks submit but I never get any emails, what am I missing out?
<?php
// Replace this with your own email address
$siteOwnersEmail = 'email#domain.com';
if($_POST) {
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
And this is the contact form:
<form name="contactForm" id="contactForm" method="post" action="mail/mail.php">
<fieldset>
<div class="form-field">
<input name="contactName" type="text" id="contactName" placeholder="Name" value="" minlength="2" required="">
</div>
<div class="form-field">
<input name="contactEmail" type="email" id="contactEmail" placeholder="Email" value="" required="">
</div>
<div class="form-field">
<input name="contactSubject" type="text" id="contactSubject" placeholder="Subject" value="">
</div>
<div class="form-field">
<textarea name="contactMessage" id="contactMessage" placeholder="message" rows="10" cols="50" required=""></textarea>
</div>
<div class="form-field">
<button type="submit" name="submit" value="send"class="submitform">Submit</button>
<div id="submit-loader">
<div class="text-loader">Sending...</div>
<div class="s-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</fieldset>
</form>
All the messages work, am I missing out on some SMPT information or something? Are there any alternatives to using phpmailer for this job?
For sending mail u need to use any of the mail service provider.
Well for mail to work your server has to have a correct configuration. Since I suspect this is a local environment I doubt it is. You best shot is using a mail library or a mail api service.
Most common php library for mailing with smtp authentication is probably
https://github.com/PHPMailer/PHPMailer
For api mail services I recommend searching on google there are plenty of alternatives
When i am replacing the email with my email id, it shows "?ok" and if i am leaving it default it shows "Your emails was Sent Successfully"
i guess there is something wrong with php code, when i edit it shows "?ok", and when i reset it back it agains shows "?ok" until i don't upload the original file which i edited (it has same code, just not opened or edited)
Here is my Php code:
<?php
// Replace this with your own email address
$siteOwnersEmail = 'user#website.com';
if($_POST) {
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
HTML CODE:
<div class="contact-primary">
<h3 class="h6">Send Us A Message</h3>
<form name="contactForm" id="contactForm" method="post" action="" novalidate="novalidate">
<fieldset>
<div class="form-field">
<input name="contactName" type="text" id="contactName" placeholder="Your Name" value="" minlength="2" required="" aria-required="true" class="full-width">
</div>
<div class="form-field">
<input name="contactEmail" type="email" id="contactEmail" placeholder="Your Email" value="" required="" aria-required="true" class="full-width">
</div>
<div class="form-field">
<input name="contactSubject" type="text" id="contactSubject" placeholder="Subject" value="" class="full-width">
</div>
<div class="form-field">
<textarea name="contactMessage" id="contactMessage" placeholder="Write us a summary for your business and what we can do to help" rows="10" cols="50" required="" aria-required="true" class="full-width"></textarea>
</div>
<div class="form-field">
<button class="full-width btn--primary">Submit</button>
<div class="submit-loader">
<div class="text-loader">Sending...</div>
<div class="s-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</fieldset>
</form>
<!-- contact-warning -->
<div class="message-warning">
Something went wrong. Please try again.
</div>
<!-- contact-success -->
<div class="message-success">
Your message was sent, thank you!<br>
</div>
</div> <!-- end contact-primary -->
Please suggest what are the changes i need to do to make work.
you can check here how error shows https://freesoft64.com/test.html
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I was working on my own vCard/resume website.
But I am having some trouble with my .php file and contact form.
I tried to debug it but I had no success.
Here is my form in html
<!-- form -->
<form name="contactForm" id="contactForm" method="post" action="inc/sendEmail.php">
<fieldset>
<div class="form-field">
<input name="contactName" type="text" id="contactName" placeholder="Name" value="" minlength="2" required>
</div>
<div class="form-field">
<input name="contactEmail" type="email" id="contactEmail" placeholder="Email" value="" required>
</div>
<div class="form-field">
<input name="contactSubject" type="text" id="contactSubject" placeholder="Subject" value="">
</div>
<div class="form-field">
<textarea name="contactMessage" id="contactMessage" placeholder="Message" rows="10" cols="50" required></textarea>
</div>
<div class="form-field">
<button class="submitform">Submit</button>
<div id="submit-loader">
<div class="text-loader">
Sending...
</div>
<div class="s-loader">
<div class="bounce1">
</div>
<div class="bounce2">
</div>
<div class="bounce3">
</div>
</div>
</div>
</div>
</fieldset>
</form>
<!-- Form End -->
And my php file
<?php
// Replace this with your own email address
$siteOwnersEmail = 'someone#example.com';
if($_POST) {
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
Can someone tell me what I am doing wrong here, because it isn't sending any emails.
Please try this
<?php
$message ="";
if(isset($_POST)){
mail(to,subject,message,headers,parameters);
}
?>
You have to declare type of button type="submit" OR type="button"
in this case work with form so you have to add type="submit"
and check user click button or direct access of file you can check !empty($_POST) with if
// Change in your HTML
<button class="submitform">Submit</button>
// to
<button type="submit" class="submitform">Submit</button>
//Change in your PHP
if($_POST)
// to
if(!empty($_POST))
I have been working on a website recently from a website template (Puremedia). The template originally had a working contact form. It consisted of "First name", "last name", "Email" and "Subject". And then of course the message. I have now replaced the "Last name" text-box with a dropdown menu. I have done so by using the html select tags. Now my question is how I would change the php scripting so that instead of sending the message (Contact form) to One predefined email. It can send it to two different email adresses. How I would like it to be implemented would be using the dropdown menu. So for example the dropdown menu would be someling along these lines: "Choose Receiver" , "Mail 1" , "Mail 2".
And then also adding a checkbox below the message field that will send a copy to the persons own email address. - Here is my contact form code:
<form name="contactForm" id="contactForm" method="post" action="">
<fieldset>
<div class="row">
<div class="six columns mob-whole">
<label for="contactFname">First Name <span class="required">*</span></label>
<input name="contactFname" type="text" id="contactFname" placeholder="First Name" value="" />
</div>
<div class="six columns mob-whole">
<select name="mailacc">
<option value="1">Send til (Vælg venligst)</option>
<option value="2">Direktør</option>
<option value="3">Bogholder</option>
</select>
</div>
</div>
<div class="row">
<div class="six columns mob-whole">
<label for="contactEmail">Email <span class="required">*</span></label>
<input name="contactEmail" type="text" id="contactEmail" placeholder="Email" value="" />
</div>
<div class="six columns mob-whole">
<label for="contactSubject">Subject</label>
<input name="contactSubject" type="text" id="contactSubject" placeholder="Subject" value="" />
</div>
</div>
<div class="row">
<div class="twelve columns">
<label for="contactMessage">Message <span class="required">*</span></label>
<textarea name="contactMessage" id="contactMessage" placeholder="Your Message" rows="10" cols="50" ></textarea>
</div>
</div>
<div>
<button class="submit full-width">Send Message</button>
<div id="image-loader">
<img src="images/loader.gif" alt="" />
</div>
</div>
</fieldset>
</form> <!-- /contactForm -->
<!-- message box -->
<div id="message-warning"></div>
<div id="message-success">
<i class="fa fa-check"></i>Your message was sent, thank you!<br />
</div>
</div> <!-- /contact-form -->
The PHP part:
<?php
// Replace this with your own email address
$siteOwnersEmail = 'mail#domain.com';
if($_POST) {
$fname = trim(stripslashes($_POST['contactFname']));
$lname = trim(stripslashes($_POST['contactLname']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check First Name
if (strlen($fname) < 2) {
$error['fname'] = "Please enter your first name.";
}
// Check Last Name
if (strlen($lname) < 2) {
$error['lname'] = "Please enter your last name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Name
$name = $fname . " " . $lname;
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }
} # end if - no validation error
else {
$response = (isset($error['fname'])) ? $error['fname'] . "<br /> \n" : null;
$response .= (isset($error['lname'])) ? $error['lname'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
Hi all i have designed a page which has online registration form, i want filled form data to be sent to email id, for that i have used below code,
$to = 'example#example.com';
$subject = 'I need to show html';
$from ='from#from.com';
$body = '<p style=color:red;>This text should be red</p>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
I have hosted this using free web hosting to test, everything works fine but submitted details doesnt come mentioned email id, i am really new to this ,can some one help me out
Here is the Form Code:
<body>
<?php
// define variables and set to empty values
$nameErr = $cnameErr = $mobilenoErr = $emailErr = $cityErr= $postalcodeErr = $addressErr = "";
$name = $cname = $mobileno = $email = $city= $postalcode = $address = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["cname"])) {
$cnameErr = "Company Name is required";
} else {
$cname = test_input($_POST["cname"]);
}
if (empty($_POST["mobileno"])) {
$mobilenoErr = "Mobile Number is required";
}else {
$mobileno = test_input($_POST["mobileno"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[789][0-9]{9}$/",$mobileno)) {
$mobilenoErr = "Not A Valid Number";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["city"])) {
$cityErr = "City is required";
} else {
$city = test_input($_POST["city"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$city)) {
$cityErr = "Only letters and white space allowed";
}
}
if (empty($_POST["postalcode"])) {
$postalcodeErr = "Postal Code is required";
} else {
$postalcode = test_input($_POST["city"]);
}
if (empty($_POST["address"])) {
$addressErr = "Address is required";
} else {
$address = test_input($_POST["address"]);
}
}
$to = 'example#Example.com';
$subject = 'I need to show html';
$from ='from#from.com';
$body = '<p style=color:red;>This text should be red</p>';
$body .= '<label>User Name:</label>'.$name.'<br>';
$body .= '<label>Company Name:</label>'.$cname.'<br>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(!empty($name)&& !empty($cname)&&!empty($mobileno)&& !empty($email)&&!empty($city)&&!empty($postalcode)&&!empty($address)){
header('Location: Submission.php?$submit=1');
exit();}
?>
<div class="gridContainer clearfix">
<div id="div1" class="fluid"><!-- header ends here-->
<div id="header" class="fluid">
<div class="fluid logo_container zeroMargin_tablet">
<div class="fluid logo_mvc"></div>
<!-- logo_mvc ends here-->
<div class="fluid logo_gsm"></div>
<!-- logo_gsm ends here-->
</div>
<!-- logo_container ends here-->
</div>
<div class="fluid imageslide zeroMargin_desktop">
<div class="fluid imageslide_gs zeroMargin_desktop"></div>
<!-- imageslide_gs ends here-->
<div class="fluid imageslide_content">
<h1>IP Product Introduction and VoIP PBX
Appliance Training Day # Toronto</h1>
</div><!-- imageslide_content ends here-->
<div class="fluid imageslide_product"></div>
<!-- imageslide_product ends here-->
</div><!-- imageslide ends here-->
<div class="fluid content">
<div class="fluid content_det">
<h3>Event information</h3>
<p>Please join us at the Fairfield Inn & Suites Toronto Airport where Grandstream will offer four different sessions during the day. </p>
<h3>Introduction to Grandstream IP products</h3>
<p><b>8:45am - 10:15am</b><br/>
Introduction to Grandstream, and basic information on Grandstream products including ATAs, gateways, routers and telephones. </p>
<h3>Introduction to IP cameras IP and Surveillance products</h3>
<p><b>12:45pm - 2:15pm</b><br/>
Basic information on IP cameras and surveillance products, and the introduction of the brand new GVR3550 Network Video Recorder. </p>
<h3>Advanced Technical Training for UCM VoIP PBX's</h3>
<p><b>2:30pm - 4:30pm</b><br/>
This session will focus on the advanced features of the UCM series, including the new features of the upcoming software and the brand new UCM6510 VoIP PBX for T1 networks. </p>
</div><!-- content_det ends here--><div class="fluid contet_form">
<h2>Register Now</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="fluid div_form"><label><b>First name *:</b></label>
<input type="text" size="20px" name="name" placeholder="Enter Your Name Here" value="<?php echo $name; ?>"/><span class="error"><?php echo $nameErr;?></span>
</div>
<div class="fluid div_form"><label><b>Company Name *:</b></label>
<input type="text" size="20px" name="cname" placeholder="Enter Your Company Name Here" value="<?php echo $cname; ?>"/><span class="error"><?php echo $cnameErr;?></span></div>
<div class="fluid div_form"><label><b>Mobile Number *:</b></label>
<input type="text" size="20px" name="mobileno" placeholder="Enter Your Mobile Number Here" value="<?php echo $mobileno; ?>"/><span class="error"><?php echo $mobilenoErr?></span>
</div>
<div class="fluid div_form"><label><b>Email Id *:</b></label>
<input type="email" size="20px" name="email" placeholder="Enter Your Email Id Here" value="<?php echo $email; ?>"/><span class="error"><?php echo $emailErr?></span></div>
<div class="fluid div_form"><label><b>City *:</b></label>
<input type="text" size="20px" name="city" placeholder="Enter Your City Name Here" value="<?php echo $city;?>"/><span class="error"><?php echo $cityErr?></span></div>
<div class="fluid div_form"><label><b>Postal Code *:</b></label>
<input type="text" size="20px" name="postalcode" placeholder="Enter Postal Code Here" value="<?php echo $postalcode; ?>"/><span class="error"><?php echo $postalcodeErr?></span>
</div>
<div class="fluid div_form"><label><b>Address *:</b></label>
<input type="text" size="20px" name="address" placeholder="Enter Address Here" value="<?php echo $address; ?>"/><span class="error"><?php echo $addressErr?></span></div>
<button name="submit" >Submit</button>
</form>
</div><!-- contet_form ends here-->
</div><!-- content ends here-->
</div><!-- div1 ends here-->
</div>
</body>
And here Submission.php Code
<?php
$submit=1;
if( !isset($_POST[$submit]) )
{
}
else{
header('Location:index.php');
exit;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Thank You For Registration</title>
</head>
<body>
<h4>Registration Sucessfull</h4><br/>
Go To Registration Page
</body>
</html>
First The problem is its an html email so use correct headers for it and then send the form data which you want in the body of html file
Test with this and let me know whether its working
$to = 'from#from.com';
$subject = 'I need to show html';
$from ='from#from.com';
ini_set("sendmail_from", $from);
$username=$_POST['name'];
$mobilenum=$_POST['mobileno'];
$cname=$_POST['cname'];
$address=$_POST['address'];
$postalcode=$_POST['postalcode'];
$headers = "From: " .$from. "\r\n";
$headers .= "Reply-To: ".$from. "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body = '<p style=color:red;>This text should be red</p>';
$body.='<label>User Name:</label>'.$username.'<br>';
$body .= '<label>Mobile Num:</label>'.$mobilenum.'<br>';
$body .= '<label>Company Name:</label>'.$cname.'<br>';
$body .= '<label>Address:</label>'.$address.'<br>';
$body .= '<label>Postalcode:</label>'.$postalcode.'<br>';
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}