Jump to content

Recommended Posts

i have include both my php code and the html form i'm pulling my hair out i just don't understand someone please help

 

 

here is my php code

<?php

// ------------- CONFIGURABLE SECTION ------------------------

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto		= "youremailaddress@example.com" ;

$mailto = 'yourname@example.com' ;

// $subject - set to the Subject line of the email, eg
//$subject	= "Feedback Form" ;

$subject = "site name" ;

// the pages to be displayed, eg
//$formurl		= "http://www.example.com/feedback.html" ;
//$errorurl		= "http://www.example.com/error.html" ;
//$thankyouurl	= "http://www.example.com/thankyou.html" ;

$formurl = "http://feedback formurl" ;
$errorurl = "http://errorpage" ;
$thankyouurl = "http://thanks page" ;

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>


here is html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="../formfile/feedback.php" method="post">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
<tr><td>Name:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Email address:</td><td><input type="text" name="email" size="25" /></td></tr>
<tr>
<td colspan="2">
Comments<br />
<textarea rows="15" cols="45" name="comments"></textarea>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Send Feedback" /><br />

</td>
</tr>
</table>
</form>



</body>
</html>

 

EDITED: Please use the code (


) tags when posting code. Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/43538-solved-form-wont-work-help/
Share on other sites

Here s a better version for ur email form

 

your html page with nice validation

 


<?php include("send_email.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post">
<?php 
if(@$_POST['sendEmail'] && (count($errors) > 0)) {
echo "   <strong>The following errors must be corrected:</strong>";
foreach($errors as $key => $err) {
echo "<strong>•</strong> " . $err;
}
echo "<br /><br />";
}
?>
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
<tr><td>Name:</td><td><input type="text" name="name" value="<?php if(isset($name)) echo $name; ?>" size="25" /></td></tr>
<tr><td>Email address:</td><td><input type="text" name="email" <?php if(isset($email)) echo $email; ?> size="25" /></td></tr>
<tr>
<td colspan="2">
Comments<br />
<textarea rows="15" cols="45" name="comments"><?php if(isset($comments)) echo $comments; ?></textarea>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="sendEmail" value="Send Feedback" /><br />

</td>
</tr>
</table>
</form>



</body>
</html>


 

and heres the page that sends the email, keep them in the same folder

 

 

send_email.php


<?php 
if(@$_POST['sendEmail']) {	

$name    = trim($_POST['name']);
$email    = trim($_POST['email']);
$comments    = trim($_POST['comments']);
    
//---------------------------------------------------------------
///*
$errors = array();

if(empty($name) || $name == "") {
	$errors[] = "Please, type your name";
}

if(!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,5}$", $email) || $email == "") {
	$errors[] = "Please, Type a valid email address";
}
if(empty($comments) || $comments == "") {
	$errors[] = "Please, type your comments";
}

// if count error greater then 0 then show error
if(count($errors) > 0)	{
return false;
} 

else {

// this part sends the email
//change this to your email.
$myEmail = "myemail@domain.com";
$site_name = "my site dot com";
$no_reply = "$name <$email>";

// This is the navn of this message
$subject= "E-mail sent vi $site_name";
// Headers will included The From, Return Email
$header = "Return-Path: $no_reply>\r\n"; 
$header .= "From: $no_reply\r\n"; 
$header .= "Content-Type: text/html; charset=iso-8859-1;\n\n\r\n";

   
//begin message admin
// if header is set to text/html then u can use the html below like usual html coding with no escape
// if header is set to text/plain use this block

// $message = "";
// $message .= "";
// $message .= "";
// $message .= "";


$message = <<<EOF

<table bgcolor="#f6f6f6" width="600" border="0" cellspacing="2" cellpadding="10" style="font-family: verdana, arial, helvetica; font-size:12px; border:2px solid #9da5b8;">

  <tr bgcolor="#FAFAFA">
    <td height="30" colspan="2"><h4><br>Email sent via $site_name!</h4></td>
  </tr>
  
  <tr bgcolor="#FAFAFA">
    <td height="30"><strong>Name:</strong></td>
    <td>$name</td>
  </tr>
  
  <tr bgcolor="#FAFAFA">
    <td height="30"><strong>Email:</strong></td>
    <td><a href="mailto:$email2">$email</a></td>
  </tr>
  
  <tr bgcolor="#FAFAFA">
    <td height="30" colspan="2"><strong style="text-decoration: underline;">Comment:</strong><br><br> $comments</td>
  </tr>
  
</table>
EOF;


// send the email
mail($myEmail,$subject,$message,$header);

// redirect to current page so if we click the refresh button
// the form won't be resubmitted ( as that would make duplicate entries )
header("Location: thankyoupage.php");
    
// force to quite the script. if we don't call exit the script may
// continue before the page is redirected
exit;
}
}

?>

 

I saw that u solved ur problem, but maybe this helps you more

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.