I want to use php and HTML to create a contact page so users can send me an message directly from the website to my email-account
The only problem I have is that, it doesn't send any messages to my email-inbox(no errors on page)
Here is the code:
HTML(no css style): INDEX.html
<!DOCTYPE html >
<html>
<head>
<title>Contact US</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="page-wrap">
<div id="contact-area">
SEND US A MESSAGE:
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
</div>
</div>
</body>
</html>
PHP: contactengine.php
<?php
$EmailFrom = "JhonDoe#domain.com";<-- not sure about this one
$EmailTo = "MyEmail#domain.com";
$Subject = "WebSite Message";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
?>
Related
I am trying to fetch "user information" on my mail id through the "mail()" function in php.the mail() function worked fine previously but now it's not working.Here is my HTML code:
<form name="contactForm" class="standard-form row-fluid" action="contact.php" method="post" >
<input class="span6" name="themeple_name" placeholder="Name" type="text" id="themeple_name" value="" / style="float:left; background-color:#fff;">
<input class="span6" name="themeple_email" placeholder="E-Mail" type="text" id="themeple_email" value="" / style="background-color:#fff;">
<input class="span6" name="themeple_subject" placeholder="Subject" type="text" id="themeple_subject" value="" required>
<textarea class="span12" placeholder="Message" name="themeple_message" cols="40" rows="7" id="themeple_message" style="background-color:#fff;"></textarea>
<p class="perspective">
<input type="submit" value="Submit Form" class="btn-system normal default" /> </p>
</form>
This is my php file:
<?php
$headers = "From: xyz#gmail.com";
$to = "xyz#gmail.com";
$Email = $_POST['themeple_email'];
$Name = $_POST['themeple_name'];
$Subject = $_POST['themeple_subject'];
$Message = $_POST['themeple_message'];
$subject = "Form submission";
$email_message = "Form details below. \r\n";
$email_message .= "Name: ".$Name. "\r\n";
$email_message .= "Email: ".$Email. "\r\n";
$email_message .= "subject: ".$Subject. "\r\n";
$email_message .= "Message: ".$Message. "\r\n";
mail ($to, $subject, $email_message, $headers);
header("Location: thank-you.html");
//echo "MAIL SENT " . $Name . $Email . $Phone . $Message;
?>
Thanks in advance.
I have the below html form, which when the user clicks submit, it fires the php code in contactengine.php but the values are missing from the email I get and the .txt form that is generated.
<!------------------from start------------>
<form method="POST" action="contactengine.php" class="form-inline" >
<div class="form-group">
<label>Full Name*</label><br>
<input name="full_name" type="text" class="form-control" placeholder="Full Name" id="full_name" required>
</div>
<div class="form-group">
<label>Telephone *</label><br>
<input name="contact_tel" type="text" class="form-control" placeholder="Telephone" id="contact_tel" required>
</div>
<div class="form-group">
<label>Email *</label><br>
<input name="contact_email" type="email" class="form-control" placeholder="Email Address" id="contact_email" required>
</div>
<div class="form-group">
<label>Subject of Enquiry *</label><br>
<select name="sub_enquiry" class="form-control" id="sub_enquiry">
<option value="Assesments" >Assesments</option><option value="Services" >Services</option>
<option value="Inpections" >Inpections</option>
<option value="Other" >Other</option>
</select>
</div><br> <br>
<label>Your message *</label><br>
<textarea name="contact_msg" class="form-control" rows="5" id="contact_msg" required ></textarea> <br >
<br >
<button type="submit" class="btn btn-purple" ><span class="glyphicon glyphicon-envelope"></span> Submit</button>
</form>
<!----------------------php form------------------>
<?php
$to = "xxxx#gmail.com";
$Subject = "OFSUK.ORG";
$full_name = $_POST['full_name'];
$contact_email = $_POST['contact_email'];
$contact_tel = $_POST['contact_tel'];
$sub_enquiry = $_POST['sub_enquiry'];
$contact_msg = $_POST['contact_msg'];
// validation
$validationOK=true;
if (!$validationOK) {
header("location:/error.php");
exit;
}
// prepare email body text
$Body = "";
$Body .= "\n";
$Body .= "Name: ";
$Body .= $full_name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $contact_email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $contact_tel;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $sub_enquiry;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $contact_msg;
$Body .= "\n";
// send email
$success = mail($to, $Subject, $Body);
$email_from = $full_name.'<'.$email_from.'>';
$myfile = fopen("emails.txt", "a") or die("Unable to open file!");
$txt = $Body;
fwrite($myfile, "\n". $txt);
fclose($myfile);
// redirect to success page
if ($success){
header("location:/");
}
else{
header("location:/contact-us.php");
}
?>
These two are stored in two locations but are working fine am just not getting any data.
Change <button type="submit" class="btn-purple"/>
To
<input type="submit" name="sbmt" class="btn-purple"/>
And then validate if sbmt has been set, if so print out the values
Try to use
pg_escape_string
like...
pg_escape_string($_POST['full_name']);
... to fix data passing problems.
I have PHP contact form and I want the Message sent or failed message to be displayed inside the main page.. I have tag after the submit button with id="notification" I want the message from send.php to be displayed inside of it.
My code is:
<form method="post" action="send.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Subject</label>
<input name="subject" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<button id="submit" name="submit" type="submit">Dergo</button>
<h3 id="notification" align="center" style="font-color:green;"></h3>
</form>
Send.php code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = 'From: KontaktFormular';
$to = 'albanianboy2#gmail.com';
$headers = "From:" . $email . "\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if(#mail($to,$subject,$body,$headers))
{
echo "Mesazhi juaj u dërgua me sukses";
}else{
echo "Gabim! Ju lutemi provoni përsëri.";
}
?>
Put your code in a PHP file.
Your code:
<?php session_start(); ?>
<form method="post" action="send.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Subject</label>
<input name="subject" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<button id="submit" name="submit" type="submit">Dergo</button>
<h3 id="notification" align="center" style="font-color:green;">
<?php
if(!empty($_SESSION["notification"])){
echo $_SESSION["notification"];
unset($_SESSION["notification"];
}
?>
</h3>
</form>
Your send.php file:
<?php
session_start();
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = 'From: KontaktFormular';
$to = 'albanianboy2#gmail.com';
$headers = "From:" . $email . "\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if(#mail($to,$subject,$body,$headers))
{
$_SESSION["notification"] = "Mesazhi juaj u dërgua me sukses";
}else{
$_SESSION["notification"] = "Gabim! Ju lutemi provoni përsëri.";
}
header("location: YOUR_PHP_FILE_WITH_THE_FORM ");
?>
Change this part of your code:
}else{
echo "Gabim! Ju lutemi provoni përsëri.";
}
to:
}else{
header('Location: mainpage.php?msg=1');
}
Then on main page, you can have:
<?php
if(isset($_GET['msg']) && $_GET['msg'] = 1)
{
?>
<h3 id="notification" align="center" style="font-color:green;">
Gabim! Ju lutemi provoni përsëri.
</h3>
<?php
}
?>
The message
$notification = "put your message";
The Javascript:
// Appeding notification to Body
$('#notification').html($notification);
Do this where you do your php check.
Put this css on top:
#notification{
display: none;
}
Setup your div
<div id="notification">
I can not get my form to send the email to me through my host server. I have run an error check using:
error_reporting( -1 );
ini_set( 'display_errors',1 );
and:
if($success){
print "EmailTo: $EmailTo<br>".
"Subject: $Subject<br>".
"Body: $Message<br>".
"From: $EmailFrom";
}
and returned the correct information.
My Code:
PHP:
<?php
$EmailFrom = Trim(stripslashes($_POST['Email']));
$EmailTo = "mclaypool#mac-av.com";
$Subject = "MAC Website Contact Form";
$Name = Trim(stripslashes($_POST['Name']));
$Address1 = Trim(stripslashes($_POST['Address1']));
$Address2 = Trim(stripslashes($_POST['Address2']));
$City = Trim(stripslashes($_POST['City']));
$State = Trim(stripslashes($_POST['State']));
$Zip = Trim(stripslashes($_POST['Zip']));
$Country = Trim(stripslashes($_POST['Country']));
$Email = Trim(stripslashes($_POST['Email']));
$Phone = Trim(stripslashes($_POST['Phone']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address1: ";
$Body .= $Address1;
$Body .= "\n";
$Body .= "Address2: ";
$Body .= $Address2;
$Body .= "\n";
$Body .= "City: ";
$Body .= $City;
$Body .= "\n";
$Body .= "State: ";
$Body .= $State;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $Zip;
$Body .= "\n";
$Body .= "Country: ";
$Body .= $Country;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\n");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MAC Production Contact Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/form.css" />
</head>
<body>
<div id="page-wrap">
<img src="images/title.gif" alt="A Nice & Simple Contact Form" /><br /><br />
<p>Please fill in the following fields and we will get back to.</p>
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Address1">Address</label>
<input type="text" name="Address1" id="Address1" />
<label for="Address2"></label>
<input type="text" name="Address2" id="Address2" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="State">State:</label>
<input type="text" name="State" id="State" />
<label for="Zip">Zip/Postal Code:</label>
<input type="text" name="Zip" id="Zip" />
<label for="Country">Country:</label>
<input type="text" name="Country" id="Country" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Phone">Phone Number:</label>
<input type="text" name="Phone" id="Phone" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div style="clear: both;"></div>
<p> </p>
</div>
</div>
The emails are not getting marked as spam. The form worked on the server when I originally created the website and sent emails without any issues. The host changed their webserver and I am assuming this is what is causing the problem, but want to make sure before I get angry with them. I have 2 forms setup on the server one is the one listed by the code entered and the other has the error reporting inserted. The 2 links are at:
http://www.mac-av.com/form/
http://www.mac-av.com/form/index_test.html
Is the email_from address getting stored correctly in database? I have had issues with this in the past where the "-" doesn't get stored.. i.e. mclaypool#mac-av.com
I'm by no means a web designer/coder, but I have enough general knowledge to get my website going. Just a simple portfolio website.
I'm having some problems with my contact form though. It's strictly CSS, HTML and PHP but when I put in the information (name, email and message) to test it, it sends me an email with those field headings, but no content. For example, the email displays as;
Name:
Email:
Message:
Even when filled out with information.
I have a feeling it's something small and a stupid error, so any help is greatly appreciated!
HTML
<div id="contact-area">
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</form>
</div>
<div id="contact-area2">
<form method="post" action="contactengine.php">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
</form>
<div id="submit-button">
<form method="post" action="contactengine.php">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
</div>
PHP
<?php
$EmailFrom = "contact#brettlair.ca";
$EmailTo = "contact#brettlair.ca";
$Subject = "Contact Form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
}
?>
You have your form fields in one form, and the submit button in another. They need to be in the same form.
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</div>
<div id="contact-area2">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
<div id="submit-button">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
$Name = Trim(stripslashes($_POST['Name']));
There is no Trim function, should be trim (lowercase).