Jump to content

Simple contact form not working


Chinx

Recommended Posts

Hi,

 

I'm new to PHP and this forum. I'd appreciate help on correcting my contact form...

I read through a few threads but couldn't understand where I needed to modify my code as they were customized.

 

I have two files. One called contact.php (with design and fields) the other contact_code.php (with php code)

 

Following code is on the design page:

 

<form method="post" action="contact_code.php">

<table align=left>

<tr>

<td width="362" class="contact-text"></td>

<td width="20"></td>

</tr>

<tr>

<td class="contact-text">Your Name</td></tr>

<td><input size=45 name="fName"></td>

</tr>

<tr>

<td class="contact-text">Email:</td></tr>

<td><input size=45 name="Email"></td>

</tr>

<tr>

<td class="contact-text">Phone:</td></tr>

<td><input size=25 name="Phone"></td>

</tr>

<tr>

<td colspan=2 class="contact-text">Message:</td></tr>

<tr><td colspan=2 align=left>

<textarea name="Message" rows=7 cols=45></textarea></td>

</tr>

<tr>

<td colspan=2 align=left>

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

</tr>

</table>

</form>

----------

Following code is on the code page:

 

<?php

$to = $_REQUEST['sendto'] ;

$from = $_REQUEST['Email'] ;

 

$fname = $_REQUEST['fName'] ;

$headers = "From: $Email";

$subject = "A message through invoridesign.com";

$fields = array();

$fields{"fName"} = "fName";

$fields{"Email"} = "Email";

$fields{"Phone"} = "Phone";

$fields{"Message"} = "Message";

$body = "We have received the following information:  "; foreach($fields as $a => $b)

{ $body .= sprintf("%20s: %s ",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";

$subject2 = "Thank you for contacting us";

$autoreply = "Thank you for contacting us";

if($from == '') {print "You have not entered an email, please go back and try again";}

else {

if($fname == '') {print "You have not entered a first name, please go back and try again";}

else {

$send = mail($to, $subject, $body, $headers);

$send2 = mail($from, $subject2, $autoreply, $headers2);

if($send)

{header( "Location: http://www.invirodesign.com" );}

else

{print "We encountered an error sending your mail, please notify [email protected]"; }

}

}

?>

 

When I post these pages online and check the form by sending myself an email, I get the following error:

We encountered an error sending your mail, please notify [email protected]

 

 

Thank you[/]

Link to comment
https://forums.phpfreaks.com/topic/150641-simple-contact-form-not-working/
Share on other sites

firstly your email is Email in your form and email in your script secondly looks like you are trying to send via sendmail through php this probably will not work need to use an address that belongs to you like info@invirodesign

 

 

Thirdly you can try this might work for you although in the header i have no idea what to put so iput what you put usually i would use

 


header ( "location: thankyou.php" );

.

And make a thankyou page

 

but you could just try this with your html form it should work

 

$email = ($_POST["Email"];
$fname = ($_POST["fName"];
$message = ($_POST["message"];

if ($Email=="")
{
print "You have not entered an email, please go back and try again";
}
if ($fName="")
{
print "You have not entered an email, please go back and try again";
}
    
header("Location: thankyou.php");

$to = "$email";
$subject = "Thank you for contacting us";
$MsgHeader  = "From: Inviro Design <[email protected]> \n";
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=iso-8859-1";
$MsgBody = "
<html>
<head>
<title>HTML message</title>
</head>
<body>
<table>
<tr><td>$fName thank you for contacting us</td></tr>
</table>

</body>
</html>";
mail($to, $subject, $MsgBody, $MsgHeader);

$to = "[email protected]";
$subject = "Thank you for contacting us";
$MsgHeader  = "From: Inviro Design <[email protected]> \n";
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=iso-8859-1";
$MsgBody = "
<html>
<head>
<title>HTML message</title>
</head>
<body>
<table>
<tr><td>$fName has sent you the following message:</td></tr>
<tr><td>$message</td></tr>
</table>

</body>
</html>";
mail($to, $subject, $MsgBody, $MsgHeader);

exit;

 

I can't see sendto in your form so i removed it, it doesn't seem to serve any purpose

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.