Tech Support Forum banner
Status
Not open for further replies.
1 - 3 of 3 Posts

· Registered
Joined
·
18 Posts
Discussion Starter · #1 ·
I have no real knowledge of PHP and had followed a tutorial on making a Contact Form. I don't remember where I got it but this is what I have so far.. For some reason its not sending a email..

contact.php

PHP:
<form action="send_contact.php" method="post" enctype="multipart/form-data" name="contact form" id="contact form">
  <table width="500" border="0" align="center" cellspacing="2" bordercolor="#FFFFFF" bgcolor="#FFFFFF" id="table1">
    <tr bordercolor="1">
      <td colspan="2"><div align="center" class="style3"><img src="extras/khswelcome.jpg" alt="Keswick High School Logo" name="KHSlogo" width="700" height="59" border="0" id="KHSlogo2" /></div></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td colspan="2" bgcolor="#cc3333"><div align="center"><span class="style3">Contact Form</span></div>        <label></label></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td colspan="2" bgcolor="#FFFFFF"><div align="left">
        <p>Please enter in your informationn below and we will get back to you as soon as possible. Please don't be afraid to email us, we will always answer back with any questions you have.</p>
        </div></td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td width="159" bgcolor="#FFFFFF"><div align="center"><strong>First Name:</strong></div></td>
      <td width="543"><input name="$name" type="text" id="$name" size="50" maxlength="20" />
* Enter your First name into the field</td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td bgcolor="#FFFFFF"><div align="center"><strong>Last Name:</strong><br />
      </div></td>
      <td><label>
        <input name="$lname" type="text" id="$lname" size="50" />
* Enter your Last name into the field</label></td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td bgcolor="#FFFFFF"><div align="center"><strong>Email:</strong></div></td>
      <td><input name="$customer_mail" type="text" id="$customer_mail" value="[email protected]" size="50" />
* Enter  email in [email protected] form</td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td bgcolor="#FFFFFF"><div align="center"><strong>Subject:</strong></div></td>
      <td><input name="$subject" type="text" id="$subject" value="Questions / Suggestions / Concerns" size="50" />
* Pick between these 3 subjects or all 3!</td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td bgcolor="#FFFFFF"><div align="center"><span class="style7">Main Content</span>:</div></td>
      <td><label>
        <textarea name="$detail" id="$detail" cols="60" rows="4">Enter your information here.</textarea>
      </label></td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td bgcolor="#FFFFFF"><div align="center"></div></td>
      <td bgcolor="#FFFFFF"><input type="submit" name="button" id="button2" value="Submit" />
      <input type="reset" name="reset2" id="reset2" value="Reset" /></td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td colspan="2" bordercolor="#000000" bgcolor="#FFFFFF"><div align="center"><a href="index.php" class="style9">Go Back to KHS Student Site</a></div></td>
    </tr>
    <tr bordercolor="#000000" bgcolor="#FFFFFF">
      <td colspan="2" bordercolor="#000000" bgcolor="#FFFFFF"><label lang="en"></label></td>
    </tr>
  </table>
</form>
send_contact.php
PHP:
<?php
// Contact subject
$subject ="$subject"; 
// Details
$message="$detail"; 

// Mail of sender
$mail_from="$customer_mail"; 
// From 
$header="from: $name $lname <$mail_from>"; 

// Enter your email address
$to ='[email protected]'; 

$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email 
// display message "We've recived your information, You will recieve a confermation email once one of the staff see it."
if($send_contact){
echo "We've recived your information, You will recieve a confermation email once one of the staff see it.";
}
else {
echo "ERROR";
}
?>
Please help i'm lost.. its for a school run site..
 

· Registered
Joined
·
899 Posts
It's not a good practice to quote your variables - so take those away. Also, you should capture your posted variables (at the top of the document)

PHP:
$subject = $_POST['subject'];
Here's a better example of what you should be doing:

PHP:
<?php
$subject = $_POST['subject']; 
$message= $_POST['message'];
$mail_from = $_POST['customer_mail'];
$name = $_POST['name'];
$lname = $_POST['lname'];

// better way to tape the header together
$header="from: " . $name . " " . $lname . " <" . $mail_from . ">";

// Enter your email address
$to = '[email protected]';

$send_contact = mail($to,$subject,$message,$header);

// Check, if message sent to your email display message else error
if($send_contact)
	{
	echo "We've received your information, You will receive a confirmation email once one of the staff see it.";
	}	else	{
	echo "There was an error sending your email. It was not sent.";
	}
?>

Let me know if that works. I don't have time to check it myself, unfortunately :wave:
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top