Log in

View Full Version : can I have two php scripts on one page<



ajfmrf
09-03-2011, 05:30 AM
I put these two scripts on one page.
submit.php


<?php
session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
echo '<strong>Incorrect verification code.</strong><br>';
} else {
// add form data processing code here
echo '<strong>Verification successful.</strong><br>';
};
?>



mail.php


<?php
$name = $_POST['name'];
$email = $_POST['email'];
$design = $_POST['design'];
$change = $_POST['change'];
$how = $_POST['how'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n How do we look: $design \n What would you Change: $change \n How did you get here: $how \n Message: $message";
$recipient = "youremailaddresshere";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We appreciate you took time to fill out our feedback form." . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>


It works but gives a warning message along with the thank you note.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/webuseri/public_html/css/5/mail2.php:13) in /home/webuseri/public_html/css/5/mail2.php on line 15



<?php
$name = $_POST['name'];
$email = $_POST['email'];
$design = $_POST['design'];
$change = $_POST['change'];
$how = $_POST['how'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n How do we look: $design \n What would you Change: $change \n How did you get here: $how \n Message: $message";
$recipient = "aflorkoski6821@tvcconnect.net";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We appreciate you took time to fill out our feedback form." . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";

session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
echo '<strong>Incorrect verification code.</strong><br>';
} else {
// add form data processing code here
echo '<strong>Verification successful.</strong><br>';
};
?>


Can this warning be eliminated or do I have to find a way to use two "action="" in the form or something??

Bud

jscheuer1
09-03-2011, 08:26 AM
Yes and how you do that depends upon what you want to have happen when verification fails.

Do you still want the email to be sent? The way you have the code now implies that the answer is yes, but logic could dictate otherwise.

If you do though, just do what the error message implies. Move the session_start() to the beginning.

If not, I'd probably go with something like:


<?php
session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
echo '<strong>Incorrect verification code.</strong><br>Mail not sent.';
die();
}

$name = $_POST['name'];
$email = $_POST['email'];
$design = $_POST['design'];
$change = $_POST['change'];
$how = $_POST['how'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n How do we look: $design \n What would you Change: $change \n How did you get here: $how \n Message: $message";
$recipient = "aflorkoski6821@tvcconnect.net";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error Sending Mail!");
echo "Thank You! We appreciate you took time to fill out our feedback form." . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

ajfmrf
09-03-2011, 05:51 PM
Thanks for the adjusted script to not send the email if an error is found.

I have added more and hope to get things polished up this week end.

Again John comes through.


Bud