Sending email contact form

Nishant ShahPHP programmer
Published:
Updated:
PHP contact form that lets the user to contact the company through email contact form. A button is fixed at the bottom of site, on clicking a new window will open where a user can send the email.
Here is a code that lets the user to contact the company through email contact form. A button is fixed at the bottom of site, on clicking a new window will open where a user can send the email.
 
Create a file cform.php where a code is written for contacting through email. 
<?php if ($Submit<>"")

{ if ($email == "")
{ $message = "E-mail cannot be empty";
$msg = "Require"; }

if ($mailmessage == "" )
{ $mailfm = "Message cannot be empty";
$msg = "Require"; }

if ($msg == "")
{
$result = "E-mail : $email\n\n";
$result .= "Message : $mailmessage\n";
$to = "contact@findlogos.in";
$subject = "Live Message";
$mailheader =""; mail($to, $subject, $result, $mailheader);
$send = "Message sent successfully";
} }
?>

<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Live Message</title>
<style type='text/css'>

.cfm {
padding-top: 50px;
}
.frm {
font-family: verdana;
font-size: 15px; padding-top: 10px;
margin-left: 25px;
}

.cfrm {
font-family: verdana;
font-size: 15px;
padding-top: 25px;
margin-left: 25px;
}

#email { width: 253px;
height: 25px; margin-left:
18px;
}

textarea {
vertical-align: top;
}

#submit {
width: 80px;
height: 32px;
margin-top: 25px;
margin-left: 180px;
}

.msg {
margin-top: 50px; margin-left: 93px;
}

.message {
margin-top: 15px;
margin-left: 93px;
}

.cnfrm {
margin-top: 30px;
margin-left: 143px;
}

</style>
</head>
<body>

<form id="cfm" name="form1" method="post" action="">
<p>&nbsp</p> <p><font size="5">Use the form below to contact</font></p>
<div class="cnfrm">

<?php echo $send; ?>

</div> <div class="msg">
<?php echo $message; ?> </div>
<div class="frm">
<label>E-mail</label>
<input id="email" name="email" type="text">
</div>

<div class="message">
<?php echo $mailfm; ?>
</div>

<div class="cfrm">
<label>Message</label>
<textarea name="mailmessage" cols="29" rows="10"></textarea>
</div>
<div class="send">
<input id="submit" name="Submit" type="submit" value="Submit"> </div>

</form>
</body>
</html>

Create another file sendmessage.php and write the following code

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title></title>
<style type='text/css'>

.send {
position: fixed; bottom: 3px;
right: 15px;
}
#msg {
background: #f8bc3a;
width: 200px
height: 35px;
}
</style>
<script language="JavaScript">
function email() {
var frm = 'directories=no,location=no,menubar=no,titlebar=no,toolbar=no,scrollbars=no,status=no';
var cfrm = 'width=500,height=350';
var cnfrm = frm + ',' + cfrm;
var msg = open("http://www.company name/cform.php", 'myWin', cnfrm); }
</script>
</head>
<body>
<div class="send">
<input id="msg" value="Send Message" onclick="email();" type="submit">
</div>

</body>
</html>

Open in new window




Upload both the files in the same directory. 

A code is required to be added in an 'index' file or main page file above the "/body" code.


Write the below code above "/body" tag. <?php include("sendmessage.php"); ?>


A new window will open to send the messages.


Open the sendmessage.php file.

To open the new window, find the required code and replace url with where you have uploaded the cform.php file.

var msg = open("http://www.company name/cform.php", 'myWin', cnfrm);
 

Open the cform.php file.


To receive the e-mail, find the required code.

$to = "yourname@yourcompany.com";


In the above code, replace the above id with the e-mail id where you want to receive the e-mail.


If your require to change the subject, find the required code.

$subject ="Live Message";


In the above code, replace the subject "Live Message" with your company name or any other subject.
 

Conclusion - Hope this will be useful to you.
0
816 Views
Nishant ShahPHP programmer

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.

Get access with a 7-day free trial.
You Belong in the World's Smartest IT Community