Jump to content

[SOLVED] Mailing Script Modification Problems


BenMo

Recommended Posts

Hello.  I'm trying to create a mailing form for my business webpage by modifying and expanding a free php script that I found online.  I only added some new vars and forms, but for some reason the new code doesn't seem to work.  I wanted to see if someone could skim the two pages and try to find what the crucial difference is that makes the original script work and the modified one fail (When I click send on the modified script, it sends me to the  w3.org site for some reason).

The page that works (code off of thesitewizard.com) can be found <A HREF = "http://www.jellywars.com/brb/contact.html">here</A>.  Feel free to view the source to see what's going on. the following is the php code to go along with that form.
[code]
<?
// ------------- CONFIGURABLE SECTION ------------------------
$mailto = '[email protected]' ;
$subject = "BigRedButton Feedback" ;
$formurl = "http://www.jellywars.com/brb/contact.html" ;
$errorurl = "http://http://www.jellywars.com/brb/error.html" ;
$thankyouurl = "http://www.jellywars.com/brb/thanksfeedback.html" ;
$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 ;
?>
[/code]

The page that doesn't work, which uses my modified code adding more forms, can be found <A HREF = "http://jellywars.com/brbtest/info.html">here</A>  The php script, also modified, is below.
[code]
<?
// ------------- CONFIGURABLE SECTION ------------------------
$mailto = '[email protected]' ;
$subject = "CustomGameOrder" ;
$formurl = "http://www.jellywars.com/brbtest/info.html" ;
$errorurl = "http://http://www.jellywars.com/brb/error.html" ;
$thankyouurl = "http://www.jellywars.com/brbtest/info.html" ;
$uself = 0;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$email2 = $_POST['email2'] ;
$lastname = $_POST['lastname'] ;
$gender = $_POST['gender'] ;
$mom = $_POST['mom'] ;
$dad = $_POST['dad'] ;
$hobby = $_POST['hobby'] ;
$neighborhood = $_POST['neighborhood'] ;
$message1 = $_POST['message1'] ;
$message2 = $_POST['message2'] ;
$message3 = $_POST['message3'] ;
$finalmessage = $_POST['finalmessage'] ;
$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" .
"FirstName: $name\n" .
"LastName: $lastname\n" .
"Gender: $gender\n" .
"Mom: $mom\n" .
"Dad: $dad\n" .
"Hobby: $hobby\n" .
"Neighborhood: $neighborhood\n" .
"Message1: $message1\n" .
"Message2: $message2\n" .
"Message3: $message3\n" .
"FinalMessage: $finalmessage\n" .
"Email of sender: $email\n" .
"Confirm Email: $email2\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper,
"From: \"$lastname\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;
?>
[/code]

Does anyone know why the first page works and the second page doesn't?  What can I do to make the second page correctly send me an email? 

Also, I apologize if this question isn't appropriate for this section...I saw the "how do I mail something" post in the FAQ section.  However, I don't need to know how to write new code, I need to know what's wrong with this code I already have.  I also am not very experienced at all with PHP (The additions were made with my understanding of HTML, C++, Java, etc).

Thank you all so much for your time!
Hi,
Me too got same error, that is direct to error page.
I found the error because in you checking part
that is    "|| empty($comments)", you checked this, but " $_POST['comments']" is empty always ,that is why directed to error.html

I deleted that condition and now working correctly.
I think that was your problem
below i pasted corrected code.
try this


<?
// ------------- CONFIGURABLE SECTION ------------------------
$mailto = '[email protected]' ;
$subject = "CustomGameOrder" ;
$formurl = "http://www.jellywars.com/brbtest/info.html" ;
$errorurl = "http://http://www.jellywars.com/brb/error.html" ;
$thankyouurl = "http://www.jellywars.com/brbtest/info.html" ;
$uself = 0;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$email2 = $_POST['email2'] ;
$lastname = $_POST['lastname'] ;
$gender = $_POST['gender'] ;
$mom = $_POST['mom'] ;
$dad = $_POST['dad'] ;
$hobby = $_POST['hobby'] ;
$neighborhood = $_POST['neighborhood'] ;
$message1 = $_POST['message1'] ;
$message2 = $_POST['message2'] ;
$message3 = $_POST['message3'] ;
$finalmessage = $_POST['finalmessage'] ;
$comments = $_POST['comments'] ;

$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email)) {
  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" .
"FirstName: $name\n" .
"LastName: $lastname\n" .
"Gender: $gender\n" .
"Mom: $mom\n" .
"Dad: $dad\n" .
"Hobby: $hobby\n" .
"Neighborhood: $neighborhood\n" .
"Message1: $message1\n" .
"Message2: $message2\n" .
"Message3: $message3\n" .
"FinalMessage: $finalmessage\n" .
"Email of sender: $email\n" .
"Confirm Email: $email2\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper,
"From: \"$lastname\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;
?>



Regards
Vijay

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.