Help please with PHP contact form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vizzo
Forum Newbie
Posts: 2
Joined: Tue Nov 24, 2009 10:20 am

Help please with PHP contact form

Post by vizzo »

I've read the posting guidelines, but being a bit thick, I'm not sure if i'm doing this right! I don't know anything about php. I've got this very simple contact form that was designed by someone else. It displays a confirmation message but I need it to send a confirmation email as well.

The form is:
<form id="form1" name="form1" method="post" action="feedback.php">
<table cellspacing="0" cellpadding="0" class="form">
<tr>
<td style="width:233px; height:107px"><table cellspacing="0" cellpadding="0">
<tr>
<td style="width:233px; height:23px"><input name="Name" type="text" id="Name" value="First Name "></td>
</tr>
<tr>
<td style="width:233px; height:23px"><input name="Surname" type="text" id="Surname" value="Surname "></td>
</tr>
<tr>
<td style="width:233px; height:23px"><input name="Phone Number" type="text" id="Phone Number" value="Phone "></td>
</tr>
<tr>
<td style="width:233px; height:23px"><p>
<input name="Email" type="text" id="Email" value="Email ">

The processor is

Code: Select all

<?
 
if (empty($_POST)) {
 print "Error with form, please contact the webmaster.";
} else {
 
 
// Configuration Settings
$SendFrom =    "Waiting List Application Form<info@a.co.uk>";
$SendTo =      "info@a.co.uk";
$SubjectLine = " Web Site";
$ThanksURL =   "thankyou2.html";  //confirmation page
$Divider =     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
 
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
   $MsgBody .= "$Field: $Value\n";
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody);  //make content safe
 
// Send E-Mail and Direct Browser to Confirmation Page
 
 
 
 mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
 header("Location: $ThanksURL");
}
?>
vizzo
Forum Newbie
Posts: 2
Joined: Tue Nov 24, 2009 10:20 am

Re: Help please with PHP contact form

Post by vizzo »

I tried this but it didn't work (I've edited out the full email address for these posts)

Code: Select all

 
<?
 
if (empty($_POST)) {
 print "Error with form, please contact the webmaster.";
} else {
 
 
// Configuration Settings
$SendFrom =    "Website Contact Form <info@a.co.uk>";
$SendTo =      "info@a.co.uk";
$SubjectLine = "AWeb Site";
$ThanksURL =   "thankyou.html";  //confirmation page
$Divider =     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
 
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
   $MsgBody .= "$Field: $Value\n";
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody);  //make content safe
 
// Send E-Mail and Direct Browser to Confirmation Page
 
 
 
 
 
$user = "$Email";
$usersubject = "Thank You";
$userheaders = "From: info@a.co.uk"; 
 
$usermessage = "Thank you for contacting us - we will be in touch shortly.";
 
 
mail($user,$usersubject,$usermessage,$userheaders); 
 
 
 header("Location: $ThanksURL");
}
Any help would be much appreciated - but please remember i'm an idiot when it comes to php!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Help please with PHP contact form

Post by superdezign »

What is the problem? That no e-mail is being sent?

This is due to your server not having an SMTP connection, as far as I know. When it has no means of sending an e-mail, it doesn't You need to either set up a connection in your actual server, or make a connection in PHP. I don't know the details of doing so, but I do know that SwiftMailer has the capability.
Post Reply