Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 08-13-2014, 09:52 AM
White Hat World White Hat World is offline
Junior Member
 
Join Date: 08-13-14
Posts: 4
iTrader: 0 / 0%
contact form

How to make php contact form. Can help anyone.
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 08-14-2014, 01:30 AM
melissawetzel melissawetzel is offline
Contributing Member
 
Join Date: 08-08-14
Posts: 51
iTrader: 0 / 0%
added code tags

Following is the sample form. You can edit it as your need.

PHP Code:
<?php 
if ($_POST["email"]<>'') { 
    
$ToEmail 'youremail@site.com'
    
$EmailSubject 'Site contact form'
    
$mailheader "From: ".$_POST["email"]."\r\n"
    
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"
    
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"
    
$MESSAGE_BODY "Name: ".$_POST["name"].""
    
$MESSAGE_BODY .= "Email: ".$_POST["email"].""
    
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""
    
mail($ToEmail$EmailSubject$MESSAGE_BODY$mailheader) or die ("Failure"); 
?> 
Your message was sent
<?php 
} else { 
?> 
<form action="test.php" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form> 
<?php 
}; 
?>

Last edited by ScriptMan; 08-14-2014 at 04:39 AM.
 
Reply With Quote
  #3  
Old 09-07-2014, 12:11 AM
arunthomas203 arunthomas203 is offline
Contributing Member
 
Join Date: 06-24-14
Posts: 68
iTrader: 0 / 0%
Also try

easyphpcontactform.com
freecontactform.com etc
 
Reply With Quote
  #4  
Old 09-13-2014, 02:09 AM
gyanender's Avatar
gyanender gyanender is offline
Contributing Member
 
Join Date: 08-19-14
Location: Ludhiana
Posts: 104
iTrader: 0 / 0%
To make a contact form you should take the help from w3school.com. Here you can get the solution about PHP problem.
 
Reply With Quote
  #5  
Old 09-14-2014, 06:30 PM
MayLamMat MayLamMat is offline
Junior Member
 
Join Date: 09-14-14
Location: http://www.muntersvn.com
Posts: 1
iTrader: 0 / 0%
Contact form used simple HTML code:
Quote:
<form id="contact_form" action="#" method="POST" enctype="multipart/form-data">
<div class="row">
<label for="name">Your name:</label><br />
<input id="name" class="input" name="name" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="email">Your email:</label><br />
<input id="email" class="input" name="email" type="text" value="" size="30" /><br />
</div>
<div class="row">
<label for="message">Your message:</label><br />
<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />
</div>
<input id="submit_button" type="submit" value="Send email" />
</form>
 
Reply With Quote
  #6  
Old 09-18-2014, 01:00 AM
freelance-developer's Avatar
freelance-developer freelance-developer is offline
Contributing Member
 
Join Date: 03-28-14
Posts: 105
iTrader: 0 / 0%
If you want to build a form quickly try this:
https://app.emailmeform.com/
 
Reply With Quote
  #7  
Old 09-18-2014, 03:38 AM
Veeramanikandan Veeramanikandan is offline
Junior Member
 
Join Date: 07-14-14
Posts: 13
iTrader: 0 / 0%
book-contact.php
-------------------
PHP Code:
<?php
$email_to 
"veera.quadraincorp@gmail.com";
$email_subject "Book Order";


if(isset(
$_POST['submit'])){
$c_name $_POST['name'] ;
$c_email $_POST['email'];
$title $_POST['booktitle'];
$paypal $_POST['paypaltransactionidorreceiptno'];
$date $_POST['purchasedate'];
$feedback $_POST['message'];

if(!
preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/"$useremail))
{
echo 
"Please Enter Valid Email Address";
}

else
{
$email_message .= "Name: ".$c_name."\n";
$email_message .= "Email: ".$c_email."\n";
$email_message .= "Book Title: ".$title."\n";
$email_message .= "PayPal Transaction ID or Receipt No: ".$paypal."\n";
$email_message .= "Purchase Date: ".$date."\n";
$email_message .= "Message: ".$feedback."\n";
$headers "From: $c_email;
$sent mail($email_to$email_subject$email_message$headers);

if(
$sent)
 
 {echo 
"email successfully sent"; }
 
 else
 
 {echo 
"email is not sent, there is some error!"; }

}

}
 
?>






form code
-------------
HTML Code:
<form action='echo book-contact.php' method='post'> <div> <label >Name<span>(required)</span></label> <input type='text' name='name' value='' required aria-required='true'/> </div> <div> <label >Email<span>(required)</span></label> <input type='email' name='email' value='' required aria-required='true'/> </div> <div> <label >Book Title<span>(required)</span></label> <input type='text' name='booktitle' value='' required aria-required='true'/> </div> <div> <label >PayPal Transaction ID or Receipt No.<span>(required)</span></label> <input type='text' name='paypaltransactionidorreceiptno' value='' required aria-required='true'/> </div> <div> <label >Purchase Date<span>(required)</span></label> <input type='text' name='purchasedate' value='' required aria-required='true'/> </div> <div> <label >Message<span>(required)</span></label> <textarea name='message' rows='20' required aria-required='true'></textarea> </div> <p '> <input type='submit' name="submit" value='Submit ' /> <input type='hidden' name='contact-form-id' value='684' /> <input type='hidden' name='action' value='hironiyan-book-contact-form' /> </p> </form>

Last edited by snakeair; 09-18-2014 at 05:21 AM.
 
Reply With Quote
  #8  
Old 09-22-2014, 04:48 AM
Rian125's Avatar
Rian125 Rian125 is offline
Contributing Member
 
Join Date: 08-14-14
Posts: 107
iTrader: 1 / 100%
Quote:
Originally Posted by Veeramanikandan View Post
book-contact.php
-------------------
PHP Code:
<?php
$email_to 
"veera.quadraincorp@gmail.com";
$email_subject "Book Order";


if(isset(
$_POST['submit'])){
$c_name $_POST['name'] ;
$c_email $_POST['email'];
$title $_POST['booktitle'];
$paypal $_POST['paypaltransactionidorreceiptno'];
$date $_POST['purchasedate'];
$feedback $_POST['message'];

if(!
preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/"$useremail))
{
echo 
"Please Enter Valid Email Address";
}

else
{
$email_message .= "Name: ".$c_name."\n";
$email_message .= "Email: ".$c_email."\n";
$email_message .= "Book Title: ".$title."\n";
$email_message .= "PayPal Transaction ID or Receipt No: ".$paypal."\n";
$email_message .= "Purchase Date: ".$date."\n";
$email_message .= "Message: ".$feedback."\n";
$headers "From: $c_email;
$sent mail($email_to$email_subject$email_message$headers);

if(
$sent)
 
 {echo 
"email successfully sent"; }
 
 else
 
 {echo 
"email is not sent, there is some error!"; }

}

}
 
?>






form code
-------------
HTML Code:
<form action='echo book-contact.php' method='post'> <div> <label >Name<span>(required)</span></label> <input type='text' name='name' value='' required aria-required='true'/> </div> <div> <label >Email<span>(required)</span></label> <input type='email' name='email' value='' required aria-required='true'/> </div> <div> <label >Book Title<span>(required)</span></label> <input type='text' name='booktitle' value='' required aria-required='true'/> </div> <div> <label >PayPal Transaction ID or Receipt No.<span>(required)</span></label> <input type='text' name='paypaltransactionidorreceiptno' value='' required aria-required='true'/> </div> <div> <label >Purchase Date<span>(required)</span></label> <input type='text' name='purchasedate' value='' required aria-required='true'/> </div> <div> <label >Message<span>(required)</span></label> <textarea name='message' rows='20' required aria-required='true'></textarea> </div> <p '> <input type='submit' name="submit" value='Submit ' /> <input type='hidden' name='contact-form-id' value='684' /> <input type='hidden' name='action' value='hironiyan-book-contact-form' /> </p> </form>
I'm using blogger platform so I'm using HTML..
Where can I put my email-add so that every email they sent I will received it to my email-add.?..I hope anyone can answer it.
 
Reply With Quote
  #9  
Old 11-13-2014, 02:15 AM
TechBuddy1 TechBuddy1 is offline
Contributing Member
 
Join Date: 11-04-14
Posts: 51
iTrader: 0 / 0%
Thumbs down Easy Contact form with validation

HTML Code:
<!DOCTYPE HTML> <html> <head> </head> <body> <?php // define variables and set to empty values $nameErr = $emailErr = ""; $name = $email = $message = ""; 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["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["message"])) { $comment = ""; } else { $comment = test_input($_POST["message"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP Form Validation Example</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Message: <textarea name="comment" rows="4" cols="35"></textarea> <br><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
[Removed]

Last edited by J. H. Rasmussen; 11-13-2014 at 08:12 PM. Reason: Added HTML wrapper and removed some text.
 
Reply With Quote
  #10  
Old 11-18-2014, 04:07 AM
chamath chamath is offline
Junior Member
 
Join Date: 11-17-14
Posts: 14
iTrader: 0 / 0%
THIS IS HTML FORM
HTML Code:
<form name="contactform" method="post" action="send_form_email.php"> <table width="450px"> <tr> <td valign="top"> <label for="first_name">First Name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top""> <label for="last_name">Last Name *</label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email">Email Address *</label> </td> <td valign="top"> <input type="text" name="email" maxlength="80" size="30"> </td> </tr> <tr> <td valign="top"> <label for="telephone">Telephone Number</label> </td> <td valign="top"> <input type="text" name="telephone" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="comments">Comments *</label> </td> <td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> <a href="email_form.php">Email Form</a> </td> </tr> </table> </form>

And This is PHP Script for that form

PHP Code:
<?php
 
if(isset($_POST['email'])) {
 
     
 
    
// EDIT THE 2 LINES BELOW AS REQUIRED
 
    
$email_to "you@yourdomain.com";
 
    
$email_subject "Your email subject line";
 
     
 
     
 
    function 
died($error) {
 
        
// your error code can go here
 
        
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo 
"These errors appear below.<br /><br />";
 
        echo 
$error."<br /><br />";
 
        echo 
"Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    
// validation expected data exists
 
    
if(!isset($_POST['first_name']) ||
 
        !isset(
$_POST['last_name']) ||
 
        !isset(
$_POST['email']) ||
 
        !isset(
$_POST['telephone']) ||
 
        !isset(
$_POST['comments'])) {
 
        
died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    
$first_name $_POST['first_name']; // required
 
    
$last_name $_POST['last_name']; // required
 
    
$email_from $_POST['email']; // required
 
    
$telephone $_POST['telephone']; // not required
 
    
$comments $_POST['comments']; // required
 
     
 
    
$error_message "";
 
    
$email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!
preg_match($email_exp,$email_from)) {
 
    
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    
$string_exp "/^[A-Za-z .'-]+$/";
 
  if(!
preg_match($string_exp,$first_name)) {
 
    
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
 
  }
 
  if(!
preg_match($string_exp,$last_name)) {
 
    
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
 
  }
 
  if(
strlen($comments) < 2) {
 
    
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
  }
 
  if(
strlen($error_message) > 0) {
 
    
died($error_message);
 
  }
 
    
$email_message "Form details below.\n\n";
 
     
 
    function 
clean_string($string) {
 
      
$bad = array("content-type","bcc:","to:","cc:","href");
 
      return 
str_replace($bad,"",$string);
 
    }
 
     
 
    
$email_message .= "First Name: ".clean_string($first_name)."\n";
 
    
$email_message .= "Last Name: ".clean_string($last_name)."\n";
 
    
$email_message .= "Email: ".clean_string($email_from)."\n";
 
    
$email_message .= "Telephone: ".clean_string($telephone)."\n";
 
    
$email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
     
 
// create email headers
 
$headers 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n" .
 
'X-Mailer: PHP/' phpversion();
 
@
mail($email_to$email_subject$email_message$headers);  
 
?>
 
 
 
<!-- include your own success html here -->
 
 
 
Thank you for contacting us. We will be in touch with you very soon.
 
 
 
<?php
 
}
 
?>

Last edited by J. H. Rasmussen; 11-18-2014 at 10:57 AM. Reason: Added HTML wrapper
 
Reply With Quote
  #11  
Old 11-22-2014, 09:10 PM
galaxy83's Avatar
galaxy83 galaxy83 is offline
Contributing Member
 
Join Date: 11-22-14
Location: localhost:80
Posts: 173
iTrader: 0 / 0%
Here is a php contact form that im using on my website and its cool:
Replace your_email@example.com with your email!
PHP Code:
<?php 
    
    define
("kContactEmail","your_email@example.com");
    
$error_msg 'The following fields were left empty or contain invalid information:<ul>';
    
$error false;
    
$submit $_POST['submit'];
    if (empty(
$submit)) 
        
$form_submitted false;
    else
      
$form_submitted true;
  if (
$form_submitted) {
      
$name $_POST['name'];
        
$company $_POST['company'];
        
$email $_POST['email'];
        
$phone $_POST['phone'];
        
$subject $_POST['subject'];
        
$message $_POST['message'];
        if(!
$name) { $error_msg .= "<li>Full Name</li>"$error true; }
        if(!
$email) { $error_msg .= "<li>E-mail Address</li>"$error true; }
        if(!
$subject) { $error_msg .= "<li>Subject</li>"$error true; }
        if(!
$message) { $error_msg .= "<li>Message</li>"$error true; }
        if(
$email) { if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$"$email)){ $error_msg .= "<li>E-mail Address</li>"$error true; }}
        
$error_msg .= "</ul>";
        
        
// email message if no errors occurred
        
if (!$error) {
      
// prepare message
            
$msg  "Full Name: \t $name \n";
            
$msg .= "Company: \t $company \n";
            
$msg .= "E-mail Address: \t $email \n";
            
$msg .= "Phone Number: \t $phone \n";
            
$msg .= "Message: \n---\n $message \n---\n";

            
// prepare message header
            
$mailheaders  "MIME-Version: 1.0\r\n";
            
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
            
$mailheaders .= "From: $name <$email>\r\n";
            
$mailheaders .= "Reply-To: $name <$email>\r\n"

          
// send out email
            
mail(kContactEmail$subject ,stripslashes($msg), $mailheaders);
        }
    } 
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Feaser">
<meta name="expires" content="NEVER">
<meta name="publisher" content="Feaser">
<meta name="copyright" content="Feaser">
<meta name="page-topic" content="Computer/Software/Internet">
<meta name="keywords" content="inexpensive small business web design, professional web site design company">
<meta name="description" content="inexpensive small business web design, professional web site design company">
<meta name="page-type" content="Commercial Organisation">
<meta name="audience" content="Professionals">
<meta name="robots" content="INDEX,FOLLOW">
<title>Contact Us</title>
<style type="text/css">
<!--
    td.form         { color: #606060; font-family: "Verdana","Arial"; font-size: 11; }
    td.main         { color: #000000; font-family: "Verdana","Arial"; font-size: 12; }
    font.form_check {    color: red; }
    input           { font-family: "Verdana","Arial"; color:#606060; font-size: 11px; }
    textarea        { font-family: "Verdana","Arial"; color:#606060; font-size: 11px; }
    div#form_box    { margin: 2px; width: 654px; border: 1px; border-style: solid; border-color: #606060; background: #f8f8f8; padding: 5px; }
    h1              { font-size:16; color: #606060; }
-->
</style>
</head>
<body>
<!-- box around the page -->
<center>
<div id="form_box"> 
<table border="0" width="100%" cellpadding="5" cellspacing="0" height="470">
    <tr>
        <td class="main" valign="top">
            <!-- page heading-->
            <h1>Contact Us</h1>
            <?php
                
// email was successfully send
                
if (($form_submitted) && (!$error)) {
            
?>
            <!-- display submitted data -->
            Thank you for your feedback, <?php echo $name?>.
            This is the information you submitted:<br><br><?php echo nl2br(stripslashes($msg)); ?>
            <?php    
                
}
                
// display contact form
                
else {
                    
// display error message
                    
if ($error) {    
                        echo 
"<font class='form_check'>" $error_msg "</font>\n";
                    } 
            
?>
            <!-- display form information -->
            -Please fill out and submit the form on this page to contact us.<br /> -We will get back to you 
            within 24 hours.<br />-Note that fields marked with (<font class="form_check">*</font>) are 
            required fields.<br /><br />
            <!-- display form -->
            <form action="<?php echo $PHP_SELF?>" method="post" name="contact">
            <table border="0" width="100%" cellspacing="5" cellpadding="0">
                <tr>
                    <td class="form" width="50%">
                        Full Name (<font class="form_check">*</font>)<br>
                        <input name="name" type="text" value="<?php echo $name ?>" size="40">
                    </td>
                    <td class="form">
                        Company<br>
                        <input name="company" type="text" value="<?php echo $company ?>" size="40">
                    </td>
                </tr>
            </table>
            <table border="0" width="100%" cellspacing="5" cellpadding="0">
                <tr>
                    <td class="form" width="50%">
                        E-mail Address (<font class="form_check">*</font>)<br>
                        <input name="email" type="text" value="<?php echo $email ?>" size="40">
                    </td>
                    <td class="form">
                        Phone Number<br>
                        <input name="phone" type="text" value="<?php echo $phone ?>" size="40">
                    </td>
                </tr>
            </table>
            <table border="0" width="100%" cellpacing="5" cellpadding="0">
                <tr>
                    <td class="form" width="50%">
                        Subject (<font class="form_check">*</font>)<br>
                        <input name="subject" type="text" value="<?php echo $subject ?>" size="89">
                    </td>
                </tr>
            </table>
            <table border="0" width="100%" cellspacing="5" cellpadding="0">
                <tr>
                    <td class="form">
                        Message (<font class="form_check">*</font>)<br>
                        <textarea name="message" cols="88" rows="12"><?php echo $message ?></textarea>
                    </td>
                </tr>
            </table>
            <table border="0" width="100%" cellspacing="5" cellpadding="0">
                <tr>
                    <td class="form">
                        <input name="submit" type="submit" value="Send Message">
                    </td>
                </tr>
            </table>
            </form>
            <?php
                
}
            
?>
        </td>
    </tr>
</table>
</div></center>
</body>
</html>
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
contact form silver163 Coding Forum 4 10-08-2009 12:00 PM
What's the best way to set up a Contact form??? chrisnrach17 Web Design Lobby 8 12-06-2008 02:10 AM
Contact form please help to create a contact form jennypretty Coding Forum 2 07-03-2008 07:49 AM
Need help with contact form gordon Coding Forum 9 05-13-2008 04:44 PM
Help me with a better contact form andreeam Coding Forum 4 11-18-2006 01:56 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 09:21 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC