Jump to content

PHP Contact Form


MrTL

Recommended Posts

Hi... I have just put together a website... and here is my contact page:

 

http://www.amahle.com/doglistener/simplify-02/contact.php

 

Now, as you see, the contact form is very boring... but in it's current state it works.

 

Here is the original code (working):

 

<?php 
if ($_POST["email"]<>'') { 
$ToEmail = '[email protected]'; 
$EmailSubject = 'Your Mail'; 
$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"]."<br>"; 
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?> 
Thankyou. Your message has been sent.
<?php 
} else { 
?> 
<form action="contact.php" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Phone:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email:</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 
}; 
?>		

 

Now, here is the code which came with the website template I am using for forms:

 

            <h2>Forms</h2>

            <form action="#" method="post">
            <div class="box-01">

                <p class="nomt"><strong>Your Name:</strong><br />
                <input type="text" size="65" class="input" /></p>

                <p><strong>Your E-mail:</strong><br />
                <input type="text" size="65" class="input" /></p>

                <p>Your Telephone Number:<br />
                <input type="text" size="65" class="input" /></p>

                <p><strong>Your Message:</strong><br />
                <textarea cols="95" rows="10" class="input" style="width:550px; height:150px;"></textarea></p>

                <p class="nomb"><input type="submit" value="Send message" class="input-submit" /></p>

            </div> <!-- /box-01 -->
            </form>

            <h2>Definition Lists</h2>

 

Now, how do I combine the working code (1st one posted) with the design of the second code posdted... any help is appreciated... thanks  :D

Link to comment
https://forums.phpfreaks.com/topic/204389-php-contact-form/
Share on other sites

<?php 
if ($_POST["email"]<>'') { 
$ToEmail = '[email protected]'; 
$EmailSubject = 'Your Mail'; 
$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"]."<br>"; 
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
echo 'Thankyou. Your message has been sent.';
} else { 
?> 

            <h2>Forms</h2>

            <form action="contact.php" method="post">
            <div class="box-01">

                <p class="nomt"><strong>Your Name:</strong><br />
                <input type="text" size="65" class="input" name="name"/></p>

                <p><strong>Your E-mail:</strong><br />
                <input type="text" size="65" class="input" name="email"/></p>

                <p>Your Telephone Number:<br />
                <input type="text" size="65" class="input" name="phone"/></p>

                <p><strong>Your Message:</strong><br />
                <textarea cols="95" rows="10" class="input" style="width:550px; height:150px;" name="message"></textarea></p>

                <p class="nomb"><input type="submit" value="Send message" class="input-submit" /></p>

            </div> <!-- /box-01 -->
            </form>

            <h2>Definition Lists</h2>
<?php
}
?>

 

Try that.

Link to comment
https://forums.phpfreaks.com/topic/204389-php-contact-form/#findComment-1070321
Share on other sites

<html>

<head>

<title>()</title>

</head>

 

<body>

 

<?php

if($_POST['Submit']) {

 

//COLLECT DATA

$name = $_POST['name'];

$email = $_POST['email'];

$phone = $_POST['phone'];

$message = $_POST['message'];

 

//EMAIL

$emailName = "TEST";

$emailFrom = "Email From: " . $name;

$emailSubject = $name . " - " . "SUBJECT";

$emailMessage .= "\nMessage from: " . $name;

$emailMessage .= "\nEmail Address: " . $email;

$emailMessage .= "\nPhone Number: " . $phone;

$emailMessage .= "\n\nMessage: " . $message;

 

//ERROR CHECKING

$error = '';

 

if (!$name)

$error = $error."<b>Name</b> ";

if (!$email)

$error = $error."<b>Email Address</b> ";

if (!$phone)

$error = $error."<b>Phone Number</b> ";

if (!$message)       

$error = $error."<b>Message</b> ";

 

if ($error!="")

echo "<span id='red'><font size='4'>Please fill out all required fields</font><br />$error</span>";

  else

  {

//SUBMIT & REDIRECT

mail( "[email protected]", "Subject: $emailSubject", $emailMessage, "From: $Email" );

 

echo ("Thanks!");

  }

 

}

?>

 

 

 

<form method="POST" action="form.php">

 

<table> 

  <tr>

    <td>Name:</td>

    <td><input size="25" name="name" value="<?PHP echo $_POST['name']; ?>"></td>

    <td>Email:</td>

    <td><input size="25" name="email" value="<?PHP echo $_POST['email']; ?>"></td>

    <td>Phone Number:</td>

    <td><input size="25" name="phone" value="<?PHP echo $_POST['phone']; ?>"></td>

  </tr>

  <tr>

    <td>Message:</td>

    <td><textarea size="25" name="message" value="<?PHP echo $_POST['message']; ?>"></td>

  </tr>

</table>

 

<input type="submit" name="submit" value="Submit" />

</form>

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/204389-php-contact-form/#findComment-1070327
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.