Jump to content

form problem


fazzfarrell

Recommended Posts

I have created this form, I had a simalar one that was working fine and now it does not send - or bring up any error messages just re displays the page. I have gone through the code and can't see where I am going wrong - any one help?

 

<?
// Change to your own email address
$your_email = "[email protected]";

// This is what is displayed in the email subject line
// Change it if you want
$subject = "Message via your pimped contact form";

// This is displayed when the email has been sent
$thankyou_message = "<p>Thank you. Your message has been sent.</p>";

$self = $_SERVER['REQUEST_URI'];

$name = $_POST['txtName'];
$company = $_POST['txtCompany'];
$tel = $_POST['txtTel'];
$email = $_POST['txtEmail'];
$web = $_POST['txtWeb'];
$message = $_POST['txtMessage'];
$nameR = $_POST['txtNameR'];
$companyR = $_POST['txtCompanyR'];
$telR = $_POST['txtTelR'];
$emailR = $_POST['txtEmailR'];
$webR = $_POST['txtWebR'];
$messageR = $_POST['txtMessageR'];
$sendR = $_POST['send'];

$msg="<p>Please fill in this form to refer a company.</p>";

echo ($msg);

$form = "
    <form method=\"post\" action=\"$self\">

    <p><label for=\"txtName\">YOUR DETAILS<br />
    Name:<br></label>
    <input type=\"text\" title=\"Please enter your name\" id=\"txtName\" name=\"txtName\" size=\"40\" value=\"$name\" /></p>

    <p><label for=\"txtCompany\">Company:<br></label>
    <input type=\"text\" title=\"Please enter your company name\" id=\"txtCompany\" name=\"txtCompany\" size=\"40\" value=\"$company\" /></p>

<p><label for=\"txtTel\">Telephone:<br></label>
    <input type=\"text\" title=\"Please enter your telephone number\" id=\"txtTel\" name=\"txtTel\" size=\"40\" value=\"$tel\" /></p>

<p><label for=\"txtEmail\">Email:<br></label>
    <input type=\"text\" title=\"Please enter your email address\" id=\"txtEmail\" name=\"txtEmail\" size=\"40\" value=\"$email\"/></p>

    <p><label for=\"txtWeb\">Web URL:<br></label>
    <input type=\"text\" title=\"Please enter your website url\" id=\"txtWeb\" name=\"txtWeb\" size=\"40\" value=\"$web\"/></p>

<p><label for=\"txtMessage\">Please enter your address:<br></label>
    <textarea title=\"Please enter your message\" id=\"txtMessage\" name=\"txtMessage\" rows=\"3\" cols=\"37\">$message</textarea></p>

 <p><label for=\"txtNameR\">THEIR DETAILS<br />
    Name:<br></label>
    <input type=\"text\" title=\"Please enter their name\" id=\"txtNameR\" name=\"txtNameR\" size=\"40\" value=\"$nameR\" /></p>

    <p><label for=\"txtCompanyR\">Company:<br></label>
    <input type=\"text\" title=\"Please enter your company name\" id=\"txtCompanyR\" name=\"txtCompanyR\" size=\"40\" value=\"$companyR\" /></p>

<p><label for=\"txtTelR\">Telephone:<br></label>
    <input type=\"text\" title=\"Please enter your telephone number\" id=\"txtTelR\" name=\"txtTelR\" size=\"40\" value=\"$telR\" /></p>

<p><label for=\"txtEmailR\">Email:<br></label>
    <input type=\"text\" title=\"Please enter your email address\" id=\"txtEmailR\" name=\"txtEmailR\" size=\"40\" value=\"$emailR\"/></p>

    <p><label for=\"txtWebR\">Web URL:<br></label>
    <input type=\"text\" title=\"Please enter your website url\" id=\"txtWebR\" name=\"txtWebR\" size=\"40\" value=\"$webR\"/></p>

<p><label for=\"txtMessageR\">Please enter your address:<br></label>
    <textarea title=\"Please enter your message\" id=\"txtMessageR\" name=\"txtMessageR\" rows=\"3\" cols=\"37\">$messageR</textarea></p>

    Please enter the text that you see in the image into the box below.
    
    <label> </label>
    <div class=\"captcha\"><img src=\"includes/captcha.php\" alt=\"security image\" /></div>

    <label for=\"verify\">Anti-Spam key:<br></label>
    <input type=\"text\" title=\"Please enter the anti-spam key\" name=\"verify\" id=\"verify\" size=\"40\" />
    <p><label> </label>
    <input type=\"submit\" class=\"sendbutton\" name=\"send\" value=\"Submit\" /></p>

</form>";

if($send)
{
    $valid=true;

if( !$name )
{ 
    $errmsg.="Please enter your name:<br />";
    $valid=false;
}

if( !$email )
{
    $errmsg.="Please enter your email address:<br />";
    $valid=false;
}
else
{
	$email = trim($email);
	$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+";
	$_host = "([-0-9A-Z]+\.)+";
	$_tlds = "([0-9A-Z]){2,4}$/i";

	if( !preg_match($_name."@".$_host.$_tlds,$email))
	{
		$errmsg.="Email address has incorrect format!<br />";
		$valid=false;
	}
}

if( !$message )
{ 
    $errmsg.="Please enter your message:<br />";
    $valid=false; 
}

if (empty($_POST['verify']) && $_POST['verify'] == $_SESSION['captchstr'])
{
    $errmsg.="Please enter security image:";
    $valid=false;
}
}

if( $valid !=true )
    {
echo( "<span style=\"font-weight: bold; color:red;\">".$errmsg."</span>" . $form );
    }

else {

    // Stop the form being used from an external URL
    // Get the referring URL
    $referer = $_SERVER['HTTP_REFERER'];
    // Get the URL of this page
    $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
    // If the referring URL and the URL of this page don't match then
    // display a message and don't send the email.
    if ($referer != $this_url) {
        echo "You do not have permission to use this script from another URL.<br />";
echo "If you are behind a firewall please check your referrer settings.";
        exit;
    }

    // The URLs matched so send the email
    if( mail($your_email, $subject, $message, "From: $name <$email>"));
    {
    	// Display the thankyou message
    	echo $thankyou_message;
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/90659-form-problem/
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.