You begin here:
http://home1.gte.net/dsean/misc/1.gif
If you press send without entering anything, you get this:
http://home1.gte.net/dsean/misc/2.gif
Here's what I'm seeking:
http://home1.gte.net/dsean/misc/3.gif
Can someone assist in modifying this script to function similar to the third gif? Recommendations are welcome as well!
Ash
<?php
// Define Variables //
$yourUrl = "http://www.blah.com";
// URL of the website you want to have people tell about
$webmasterEmail = "blah@blah.com";
// Your email address for notifications
$receiveNotifications = 0;
// Tells who used it and what addresses they sent it to.
// Either 1 for Yes or 0 for No.
$messagecolor = "#ff0000";
// Color of notification messages displayed on error or successful sending of message
$subject = "Website Recommendation from $yourName ($yourEmail)";
// This will be the subject that appears on sent messages
$sendMessage = "Hello,\n**YourName** thought you would like the following site:\n$yourUrl";
// This is a message that will be sent at the top of all emails
// Use \n to create a new line. **YourName** will be replaced by the name of the sender.
// Done - No need to edit below //
if($action == "go") {
if(empty($yourName)) {
$message .= "Please enter your name.<br>";
$error = 1;
}
if(empty($yourEmail)) {
$message .= "Please enter your email address.<br>";
$error = 1;
}
else {
if(!isValid($yourEmail)) {
$message .= "Please enter a proper email address for yourself.<br>";
$error = 1;
}
}
if(empty($a1) && empty($a2) && empty($a3) && empty($a4) && empty($a5)) {
$message .= "Please enter at least one friend's email address.<br>";
$error = 1;
}
// Now we will gather how many form fields are filled in and
// create an array to fill with them if the addresses are valid.
$emailList = array(); // create empty array
if(!empty($a1)) {
if(!isValid($a1)) {
$finalM .= "Email 1 was not valid and no message was sent to it.<br>";
}
else {
$amount = $amount + 1;
array_push($emailList,$a1);
}
}
if(!empty($a2)) {
if(!isValid($a2)) {
$finalM .= "Email 2 was not valid and no message was sent to it.<br>";
}
else {
$amount = $amount + 1;
array_push($emailList,$a2);
}
}
if(!empty($a3)) {
if(!isValid($a3)) {
$finalM .= "Email 3 was not valid and no message was sent to it.<br>";
}
else {
$amount = $amount + 1;
array_push($emailList,$a3);
}
}
if(!empty($a4)) {
if(!isValid($a4)) {
$finalM .= "Email 4 was not valid and no message was sent to it.<br>";
}
else {
$amount = $amount + 1;
array_push($emailList,$a4);
}
}
if(!empty($a5)) {
if(!isValid($a5)) {
$finalM .= "Email 5 was not valid and no message was sent to it.<br>";
}
else {
$amount = $amount + 1;
array_push($emailList,$a5);
}
}
reset($emailList); // Set the array pointer to the beginning
// Now if there are no errors actually send the messages.
if($error == 0) {
$sendMessage = str_replace("**YourName**",$yourName,$sendMessage);
foreach($emailList as $to) {
if(!mail($to,$subject,"$sendMessage\n\n" . $customMessage . "\n\nNote: This message was not sent unsolicited.
It was sent through a form located at [url]http://[/url]" . $_SERVER['SERVER_NAME'] . "$PHP_SELF.
If you beleive this message was received on error, please disregard it.",
"From: $yourEmail\r\n"
."Reply-To: $yourEmail\r\n"
."X-Mailer: Recommend\r\n"))
{
$finalM .= "Message was not successfully sent to ${to} for some reason. Pleas try again later.<br>";
} // != mail()
else {
$finalM .= "Message was sent to $to.<br>";
$reciplist .= " $to,"; // To be used in notifications
} // end != else
} // end foreach
} // end error if
// Thats a lot of curly braces...
if ($error == "1") {
echo "<center><font color=\"$messagecolor\">$message</font></center><br>\n";
}
if ($finalM) {
echo "<center><font color=\"$messagecolor\">$finalM<br>Thank you very much for referring us.</font></center><br>\n";
if($receiveNotifications) {
@mail($webmasterEmail,"Someone Recommended Your Site",
"Hi\nThis is a message to tell your that $yourName ($yourEmail) sent a website recommendation to$reciplist.\nEnd Message",
"From: $webmasterEmail\r\n"
."X-Mailer: Recommend");
} // end if receive notifications.
}
} // end main if
else {
echo<<<EOD
<center>
<form method="POST" action="$PHP_SELF">
<input type=hidden name=action value="go">
<center>Enter up to five friends' email addresses to send a referral to.<br><br></center>
<table border=0 cellpadding=3 cellspacing=3 align=center width=300>
<tr><td align=left>Your Name:</td>
<td align=right><input type=text name=yourName></td>
</tr>
<tr><td align=left>Your Email:</td>
<td align=right><input type=text name=yourEmail></td>
</tr>
<tr><td align=left>Friend 1:</td>
<td align=right><input type=text name=a1></td>
</tr>
<tr>
<td align=left>Friend 2:</td>
<td align=right><input type=text name=a2></td>
</tr>
<tr><td align=left>Friend 3:</td>
<td align=right><input type=text name=a3></td>
</tr>
<tr><td align=left>Friend 4:</td>
<td align=right><input type=text name=a4></td>
</tr>
<tr><td align=left>Friend 5:</td>
<td align=right><input type=text name=a5></td>
</tr>
</table>
<table border=0 cellpadding=3 cellspacing=3 width=300>
<tr><td align=center>The text below will be sent at the top
of the message your friends will receive.
<textarea name=sendMessage cols=34 rows=5 readonly>$sendMessage
</textarea></td></tr>
<tr><td align=center><textarea name=customMessage cols=34 rows=5>
Enter a personal message to your friend here if you wish.
</textarea></td></tr>
</table>
<input type=submit value="Send Message">
<input type=reset value="Start Over">
</form>
</center>
EOD;
} // end main else
function isValid($email) {
if(eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $email)) return TRUE;
else return FALSE;
}
?>