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 = 'bigredbutton@gmail.com' ;
$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 = 'bigredbutton@gmail.com' ;
$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!
Link to comment
Share on other sites

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 = 'bigredbutton@gmail.com' ;
$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
Link to comment
Share on other sites

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.