Jump to content

PHP Mail Script


uramagget

Recommended Posts

Okay, my problem right now is, that I'm having troubles with a mail form. Here is the problem.

 

I make it so all fields are required. And if none are filled out, then you're flung into a "missing fields" page. But for my form, I've filled them all out, but can't get it to work right. Here's both my HTML and PHP Code, with everything explained:

 

 

formscript.php

<?


//Let's see what ya sent in there, buddy boy
$Email = Trim(stripslashes($_POST['Email'])); 
$GameName = Trim(stripslashes($_POST['GameName'])); 
$GameURL = Trim(stripslashes($_POST['GameURL'])); 
$Description = Trim(stripslashes($_POST['Description'])); 
$ScreenshotURL = Trim(stripslashes($_POST['ScreenshotURL'])); 
$rating = Trim(stripslashes($_POST['rating']));
$compatibility = Trim(stripslashes($_POST['compatibility']));
$development = Trim(stripslashes($_POST['development'])); 

//Subject and Where to send mail to
$EmailTo = "spaceyoshix@hotmail.com";
$Subject = "Fan Game Submission";

// Validate so nothing is left empty. Absolutely nothing, except "other"
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($GameName)=="") $validationOK=false;
if (Trim($GameURL)=="") $validationOK=false;
if (Trim($Description)=="") $validationOK=false;
if (Trim($ScreenshotURL)=="") $validationOK=false;
if (Trim($Other)=="") $validationOK=false;
if (Trim($compatibility)=="") $validationOK=false;
if (Trim($rating)=="") $validationOK=false;
if (Trim($development)=="") $validationOK=false;

if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=missing.htm\">";
  exit;
}
//
// Get ready to send an email!
//

//Game Name
$Body .= "Game Name: ";
$Body .= $GameName;
$Body .= "\n";
//Game URL
$Body .= "Game URL: ";
$Body .= $GameURL;
$Body .= "\n";
//Description
$Body .= "Description: ";
$Body .= $Description;
$Body .= "\n";
//Screenshot URL
$Body .= "Screenshot URL: ";
$Body .= $ScreenshotURL;
$Body .= "\n";
//Rating
$Body .= "Rating: ";
$Body .= $rating;
$Body .= "\n";
//Compatibility
$Body .= "Compatibility: ";
$Body .= $compatibility;
$Body .= "\n";
//Development
$Body .= "Development: ";
$Body .= $development;
$Body .= "\n";
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=sent.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

 

 

index.php

<form method="POST" action="formscript.php">
<p>All Fields required.</p>


<p>Email:* </p>
<p><input type="text" name="EmailFrom"></p>
<p>Game Name:* </p>
<p><input type="text" name="GameName"></p>
<p>Game URL:* </p>
<p><input type="text" name="GameURL"></p>
<p>Description:* </p>
<input type="text" name="Description">
<p>Screenshot URL:* </p>
<input type="text" name="ScreenshotURL">
<p>Rating:* </p>
<select name="rating">
<option value="" selected>Rating</option>
<option value="E">Everyone</option>
<option value="T">Teen</option>
</select>


<p>Compatibility:*</p>
<select name="compatibility">
<option value="" selected>Compatibility</option>
<option value="Windows">Windows XP</option>
<option value="Vista">Vista</option>
<option value="Mac">Macintosh</option>
</select>

<p>Development:*</p>
<select name="development">
<option value="" selected>Development</option>
<option value="gm5">Game Maker 5-</option>
<option value="gm6">Gane Maker 6+</option>
<option value="turbopascel">Turbo Pascel</option>
<option value="flash">Flash</option>
</select>

<p><input type="submit" name="submit" value="Submit"></p>
</form>

 

 

 

If you need an exact preview, here you go:

 

 

 

 

http://www.sprites-unlimited.com/submit/

 

Link to comment
Share on other sites

I don't know but it side tracked me!

 

Rather than doing the redirect to the error page just do an echo statement on the current page... also echo out which fields are causing the errors. For example:

 

change:

if (Trim($ScreenshotURL)=="") $validationOK=false;

 

to

if (Trim($ScreenshotURL)=="") { $validationOK=false; echo "ScreenshotURL failed!<br />"; }

 

So by doing this you can find out where your culprit is.

Link to comment
Share on other sites

My problem was solved! Thanks! But, I want to give more user friendliness to my form. How would I go to creating checkboxes, instead of having to use those drop downs?

 

Here is my current PHP code, working:

 

 

<?


//Let's see what ya sent in there, buddy boy
$Email = Trim(stripslashes($_POST['Email'])); 
$GameName = Trim(stripslashes($_POST['GameName'])); 
$GameURL = Trim(stripslashes($_POST['GameURL'])); 
$Description = Trim(stripslashes($_POST['Description'])); 
$ScreenshotURL = Trim(stripslashes($_POST['ScreenshotURL'])); 
$compatibility = Trim(stripslashes($_POST['compatibility'])); 
$development = Trim(stripslashes($_POST['development'])); 

//Subject and Where to send mail to
$EmailTo = "spaceyoshix@hotmail.com";
$Subject = "Fan Game Submission";

// Validate so nothing is left empty. Absolutely nothing, except "other"
$validationOK=true;
if (Trim($EmailFrom)=="") {$validationOK=false; echo "<p>E-Mail Field Empty</p>";}
if (Trim($GameName)=="") {$validationOK=false; echo "<p>Game Name Field Empty</p>";}
if (Trim($GameURL)=="") {$validationOK=false; echo "<p>Game URL Field Empty</p>";}
if (Trim($Description)=="") {$validationOK=false; echo "<p>Description Field Empty</p>";}
if (Trim($ScreenshotURL)=="") {$validationOK=false; echo "<p>Screenshot URL Field Empty</p>";}
if (Trim($compatibility)=="") {$validationOK=false; echo "<p>Compatibility Field Empty</p>";}
if (Trim($development)=="") {$validationOK=false; echo "<p>Development Field Empty</p>"; exit;}

//if (!$validationOK) {
//  print "<meta http-equiv=\"refresh\" content=\"0;URL=missing.htm\">";
//  exit;
//}

//
// Get ready to send an email!
//

//Game Name
$Body .= "Game Name: ";
$Body .= $GameName;
$Body .= "\n";
//Game URL
$Body .= "Game URL: ";
$Body .= $GameURL;
$Body .= "\n";
//Description
$Body .= "Description: ";
$Body .= $Description;
$Body .= "\n";
//Screenshot URL
$Body .= "Screenshot URL: ";
$Body .= $ScreenshotURL;
$Body .= "\n";
//Compatibility
$Body .= "Compatibility: ";
$Body .= $compatibility;
$Body .= "\n";
//Development
$Body .= "Development: ";
$Body .= $development;
$Body .= "\n";
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page 
if ($success){
  echo "IMAH CHARGIN MAH INBOX. SHOOP DA WHOOP!\n";
  echo "Game Submission sent succesfully. Please wait for a reply from the webmaster.";
  exit;
}
else{
  echo "E-Mail could not be sent. Please send manually, or contact the webmaster regarding this mistake, courtesy of Faltzer";
exit;
}
?>

 

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.