PDA

View Full Version : Coding for my email scipt.... PLEASE HELP



lozbenson
Oct 2nd, 2009, 01:16 AM
HEY GUYS,

I have this emailing script and it works other than redirecting to the thank you page...

The site in question is...

http://www.erbimages.com/contact_pre.php

I get the emails fine, it just doesn't redirect users to the thank you page...

PLEASE HELP... THANKS...!!!

prasanthmj
Oct 2nd, 2009, 06:29 AM
Add a redirection code as shown below


header('Location: thank-you.html');


More info:
PHP email contact form (http://www.html-form-guide.com/contact-form/php-email-contact-form.html)

lozbenson
Oct 2nd, 2009, 05:06 PM
I have that it, and tried a few different thins such as use thankyou.html rather than thankyou.php

Any other clues or is there something specific that you see wrong in that header section...???

you can see the header section on www.erbimages.com/contact.php, line 31 (I believe)...

Apostropartheid
Oct 2nd, 2009, 05:12 PM
No, we can't. PHP is parsed server-side before it is delivered. You will have to post your code.

jlhaslip
Oct 2nd, 2009, 06:18 PM
preferably in the php Forum???

lozbenson
Oct 3rd, 2009, 01:45 PM
Here are the scripts...

contact_pre.php


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

<p>Your Details</p>
<p><select name="sendto"><option value="[email protected]">Information</option> <option value="[email protected]">Hire</option> <option value="[email protected]">Royalty Free</option> <option value="[email protected]">Technical</option></select></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Name:</font><input size=25 name="Name"></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Email:</font><input size=25 name="Email"></p>
<p><font style="padding-right: 2em;">Company / Event:</font><input size=25 name="Company"></p>
<p>Message</p>
<p><textarea name="Message" rows=5 cols=35></textarea></p>
<p><input type=submit name="send" value="Submit"></p>

</form>

and contact.php


<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";

if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.php" );}
else
{print "We encountered an error sending your mail, please notify [email protected]"; }
}
}
?>

abduraooft
Oct 3rd, 2009, 02:03 PM
Check http://php.net/header

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. The above php code should come at the very top of your contact.php page, before anything else.

lozbenson
Oct 3rd, 2009, 02:22 PM
I understand but don't understand how to change it... if I show you the full script do you think you could help me out... PRETTY PLEASE

This is for contact_pre.php



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>ERB Images | Quality British Photography</title>
<link rel="stylesheet" type="text/css" href="base_ff.css" media="screen">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="revisit-after" content="31 Days">
<meta name="expires" content="never">
<meta name="distribution" content="global">
<meta name="robots" content="index,follow">
</head>
<body class="fullpage">
<div class="outer">
<div class="mainbody">
<div class="header_left_home">
<ul id="home">
<li>
<a href="index.php">RETURN HOME</a>
</li>
</ul>
</div>
<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_contact"><a href="http://www.erbimages.com/hire_pre.php">GO BACK</a></span>
</li>
<li>
<span id="section_txt_form">
<form method="post" action="contact.php">
<p>Your Details</p>
<p>
<select name="sendto">
<option value="[email protected]">Information</option>
<option value="[email protected]">Hire</option>
<option value="[email protected]">Royalty Free</option>
<option value="[email protected]">Technical</option>
</select>
</p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Name:</font><input size=25 name="Name"></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Email:</font>
<input size=25 name="Email">
</p>
<p><font style="padding-right: 2em;">Company / Event:</font><input size=25 name="Company"></p>
<p>Message</p>
<p><textarea name="Message" rows=5 cols=35></textarea></p>
<p><input type=submit name="send" value="Submit"></p>
</form>
</span>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>


This is for contact.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>ERB Images | Quality British Photography</title>
<link rel="stylesheet" type="text/css" href="base_ff.css" media="screen">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="revisit-after" content="31 Days">
<meta name="expires" content="never">
<meta name="distribution" content="global">
<meta name="robots" content="index,follow">
</head>
<body class="fullpage">
<div class="outer">
<div class="mainbody">
<div class="header_left_home">
<ul id="home">
<li>
<a href="index.php">RETURN HOME</a>
</li>
</ul>
</div>
<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_contact"><a href="http://www.erbimages.com/hire_pre.php">GO BACK</a></span>
</li>
<li>
<span id="section_txt">

<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";

if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.php" );}
else
{print "We encountered an error sending your mail, please notify [email protected]"; }
}
}
?>
</span>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>

abduraooft
Oct 3rd, 2009, 02:27 PM
The following should help you to move forward
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";

if($from == '') {$error= "You have not entered an email, please go back and try again";}
else {
if($name == '') {$error ="You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.php" );}
else
{$error= "We encountered an error sending your mail, please notify [email protected]"; }
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>ERB Images | Quality British Photography</title>
<link rel="stylesheet" type="text/css" href="base_ff.css" media="screen">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="revisit-after" content="31 Days">
<meta name="expires" content="never">
<meta name="distribution" content="global">
<meta name="robots" content="index,follow">
</head>
<body class="fullpage">
<div class="outer">
<div class="mainbody">
<div class="header_left_home">
<ul id="home">
<li>
<a href="index.php">RETURN HOME</a>
</li>
</ul>
</div>
<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_contact"><a href="http://www.erbimages.com/hire_pre.php">GO BACK</a></span>
</li>
<li>
<span id="section_txt">
<?php
echo $error;
?>

</span>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
PS: Checking fields against the null character may not be enough.

lozbenson
Oct 3rd, 2009, 02:47 PM
THANKS... REALLY MAKING PROGRESS...

The only new issue is that it doesn't (unlike before) go to my page that states that they missed a field and need to go back...???

:thumbsup:

I really appropriate all your help... please don't underestimate what it means to me...

abduraooft
Oct 3rd, 2009, 03:22 PM
You don't need to have two seperate files for displaying your form and writing the php executables.

I'd use a single page contact.php having something like

//pseudo-php
if(isset($_POST['send'])){
//validate the submitted data, and save the errors in variables/arrays, if any
//send mail, in case of no errors and save the status in vavariable
}
.............
//html top portions here
.............
if(ANY errors)
//display here
if(NOT send mail){
//display form
}
elseif(mail has been send){
//display the success message here
}
//html bottom portions here

lozbenson
Oct 3rd, 2009, 03:48 PM
I see, but I dont see... I am sorry for being such a novice...

I have place this section in contact...


<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";

if($from == '') {$error= "You have not entered an email, please go back and try again";}
else {
if($name == '') {$error ="You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.php" );}
else
{$error= "We encountered an error sending your mail, please notify [email protected]"; }
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>ERB Images | Quality British Photography</title>
<link rel="stylesheet" type="text/css" href="base_ff.css" media="screen">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="revisit-after" content="31 Days">
<meta name="expires" content="never">
<meta name="distribution" content="global">
<meta name="robots" content="index,follow">
</head>
<body class="fullpage">
<div class="outer">
<div class="mainbody">
<div class="header_left_home">
<ul id="home">
<li>
<a href="index.php">RETURN HOME</a>
</li>
</ul>
</div>
<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_contact"><a href="http://www.erbimages.com/hire_pre.php">GO BACK</a></span>
</li>
<li>
<span id="section_txt">

<?php
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.php" );}
else
{print "We encountered an error sending your mail, please notify [email protected]"; }
}
}

</span>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>

OMG I feel like such an idiot... abd feel guilty for being so needy but any hints?

abduraooft
Oct 3rd, 2009, 04:16 PM
Try
<?php
if(isset($_POST['send'])){
$to = $_REQUEST['sendto'] ; // change all the following to $_POST
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";
$send=false;
if($from == '') {$error= "You have not entered an email, please go back and try again";}
else {
if($name == '') {$error= "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
if(!isset($error) && !$send)
$error= "We encountered an error sending your mail, please notify [email protected]"; }
}// end of if(isset($_POST['send']))
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>ERB Images | Quality British Photography</title>
<link rel="stylesheet" type="text/css" href="base_ff.css" media="screen">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="revisit-after" content="31 Days">
<meta name="expires" content="never">
<meta name="distribution" content="global">
<meta name="robots" content="index,follow">
</head>
<body class="fullpage">
<div class="outer">
<div class="mainbody">
<div class="header_left_home">
<ul id="home">
<li>
<a href="index.php">RETURN HOME</a>
</li>
</ul>
</div>
<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_contact"><a href="http://www.erbimages.com/hire_pre.php">GO BACK</a></span>
</li>
<li>
<span id="section_txt">


</span>
<?php
if(isset($error))
echo '<span id="section_txt">'.$error.'</span>';
if(isset($send) && $send== true){
echo 'your message has been send';
}
if(!isset($_POST['send']) || isset($error))
?>
<form method="post" action="contact.php">
<p>Your Details</p>
<p><select name="sendto"><option value="[email protected]">Information</option> <option value="[email protected]">Hire</option> <option value="[email protected]">Royalty Free</option> <option value="[email protected]">Technical</option></select></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Name:</font><input size=25 name="Name"></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Email:</font><input size=25 name="Email"></p>
<p><font style="padding-right: 2em;">Company / Event:</font><input size=25 name="Company"></p>
<p>Message</p>
<p><textarea name="Message" rows=5 cols=35></textarea></p>
<p><input type=submit name="send" value="Submit"></p>
</form>
<?php
}
?>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>

lozbenson
Oct 3rd, 2009, 05:51 PM
GREAT...

After removing the { on line 82 all worked perfectly... just need to edit the style...

THANK YOU SO MUCH :thumbsup:

lozbenson
Oct 30th, 2009, 03:16 PM
Well not quite...

It seems not to show the error messages of confirmation... give it a go, just use demo demo demo etc in the fields... I receive the email but you as a user recieve no information...

PLEASE HELP... heres the script...


<?php
if(isset($_POST['send'])){
$to = $_REQUEST['sendto'] ; // change all the following to $_POST
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";
$send=false;
if($from == '') {$error= "You have not entered an email, please go back and try again";}
else {
if($name == '') {$error= "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
if(!isset($error) && !$send)
$error= "We encountered an error sending your mail, please notify [email protected]"; }
}// end of if(isset($_POST['send']))
?>

<?php include("http://www.erbimages.com/php/head.php"); ?>
<?php include("http://www.erbimages.com/php/start.php"); ?>
<?php include("http://www.erbimages.com/php/topline/return.php"); ?>

<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_header_right_contact">CONTACT</span>
</li>
<li>
<span id="section_txt">

<?php
if(isset($error))
echo '<span id="section_error">'.$error.'</span>';
if(isset($send) && $send== true){
echo 'Your message has been send. Thank you.';
}
if(!isset($_POST['send']) || isset($error))
?>

<form method="post" action="contact.php">
<p>Your Details</p>
<p><select name="sendto"><option value="[email protected]">Information</option> <option value="[email protected]">Hire</option> <option value="[email protected]">Royalty Free</option> <option value="[email protected]">Technical</option></select></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Name:</font><input size=25 name="Name"></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Email:</font><input size=25 name="Email"></p>
<p><font style="padding-right: 2em;">Company / Event:</font><input size=25 name="Company"></p>
<p>Message</p>
<p><textarea name="Message" rows=5 cols=35></textarea></p>
<p><input type=submit name="send" value="Submit"></p>
</form>
</span>
</li>
</ul>
</div>

<?php include("http://www.erbimages.com/php/quiet_footer.php"); ?>
<?php include("http://www.erbimages.com/php/end.php"); ?>


PLEASE HELP, I REALLY NEED YOU...

lozbenson
Oct 30th, 2009, 05:50 PM
Please

lozbenson
Oct 31st, 2009, 02:05 PM
No ideas?