bradgrafelman;10976868 wrote:Your if() statement checks for $_REQUEST['email'], but there is no form entity named 'email' in the HTML code you've shown us.
Your dedication in answering these questions is enormously appreciated. I've gotten to the point where it successfully runs and is theoretically sending the email. I suppose the next step is bugging the guy whose box I'm running on to find out if the damn thing can actually send emails.
Do you happen to see any particular script based reason this wouldn't actually send? Other than me fat-fingering the email addresses?
Here's the current state of the script:
<html>
<body>
<?php
$commonMessage[0] = "This is sample message 0";
$commonMessage[1] = "This is sample message 1";
$commonMessage[2] = "This is sample message 2";
$commonMessage[3] = "This is sample message 3";
$commonMessage[4] = "This is sample message 4";
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['mailTo']))
{//if 'email' is filled out, proceed
echo "Something happened";
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['mailTo']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{//send email
$email = $_REQUEST['mailFrom'];
$subject = '*REDACTED* and ' . $_REQUEST['companyName'];
$message = $_REQUEST['message'];
$emailC = $_REQUEST['mailTo'];
mail($emailC, "Subject: $subject", $message, "From: $email" );
echo "success (in theory)!";
}
}
else
{//if 'email' is not filled out, display the form
echo "<form method='post' action='genericmail.php'>
Your Email: <input name='mailFrom' type='text' /><br />
Company: <input type='text' name='companyName'/><br />
Contact: <input type='text' name='contactName'/><br />
Contact Email: <input type='text' name='mailTo'/><br />
Region: <select name ='region'>
<option value='the United States'>United States</option>
<option value='Europe'>Europe</option>
<option value='Asia'>Asia</option>
</select>
Message:<select name ='leadType'>
<option value='sameBuilding'>We are in your building</option>
<option value='sameCity'>We are in city, not building</option>
<option value='inRegion'>We are in region, not city</option>
<option value='notInRegion'>We are not in region</option>
<option value='homeUser'>Home user</option>
</select><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>
The next step from here for me is actually adding the bells and whistles I need on this piece of script. Learning is fun, and failure is half the battle! And as long as someone else is there to help shoot down issues, it's quite nice!
Tangent to these issues, I've been writing the whole thing in Notepad++. Unlike the heinously strict compilers* for Java to which I am accustomed, it doesn't have even the slightest interest in telling me that I have screwed up, repeatedly, and how I might go about fixing it.
I see that there are similar options for PHP. Any recommendations? And are they as effective at complaining? Additionally, I think I'll go hunt down what, exactly, a scripting language needs a compiler for!
I've actually seen people complain about how voluble the Java compilers are! It blows my mind -- Eclipse alone has saved dozens of hours of my life with its nagging when compared to similar projects in C++! Initialize this, type that, don't do those, you're not using that variable, those pointers are naughty, blah blah blah. If anything, I wish the dang thing would **** more.