View Full Version : Site recommendation script (on windows server) not sending mail

09-11-2003, 02:44 AM
Ok, after a bit of reading, on a Windows server it seems you have to specify a URL=http://php.weblogs.com/stories/storyReader$67]smtp server[/URL].

That said, maybe someone could assist me in modifying this script? (If you could point out where to place the smtp server, I have it and can add it)

// Drews Recommend Site Script
// Written Febuary 27th 2003.
// http://www.drew-phillips.com

// This script looks best when called via an include tag within one of your pages.
// See Readme.txt for explanation

// Define Variables //
$yourUrl = "http://xyz.net";
// URL of the website you want to have people tell about

$webmasterEmail = "xyz@xyz.net";
// Your email address for notifications

$receiveNotifications = 1;
// 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;
if(!empty($a2)) {
if(!isValid($a2)) {
$finalM .= "Email 2 was not valid and no message was sent to it.<br>";
else {
$amount = $amount + 1;

if(!empty($a3)) {
if(!isValid($a3)) {
$finalM .= "Email 3 was not valid and no message was sent to it.<br>";
else {
$amount = $amount + 1;

if(!empty($a4)) {
if(!isValid($a4)) {
$finalM .= "Email 4 was not valid and no message was sent to it.<br>";
else {
$amount = $amount + 1;

if(!empty($a5)) {
if(!isValid($a5)) {
$finalM .= "Email 5 was not valid and no message was sent to it.<br>";
else {
$amount = $amount + 1;
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 http://" . $_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: Drew's Tell-A-Friend\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: Drew's Tell-A-Friend");
} // end if receive notifications.

} // end main if

else {
<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><td align=left>Your Email:</td>
<td align=right><input type=text name=yourEmail></td>

<tr><td align=left>Friend 1:</td>
<td align=right><input type=text name=a1></td>

<td align=left>Friend 2:</td>
<td align=right><input type=text name=a2></td>

<tr><td align=left>Friend 3:</td>
<td align=right><input type=text name=a3></td>

<tr><td align=left>Friend 4:</td>
<td align=right><input type=text name=a4></td>

<tr><td align=left>Friend 5:</td>
<td align=right><input type=text name=a5></td>
<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
<tr><td align=center><textarea name=customMessage cols=34 rows=5>Enter a personal message to your friend here if you wish.

<input type=submit value="Send Message">
<input type=reset value="Start Over">
} // end main else

function isValid($email) {
if(eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $email)) return TRUE;
else return FALSE;


09-11-2003, 01:19 PM
The page you've linked to explains how to change the smtp value in your PHP.INI file. this would be the configuration file for PHP. If you have access to this (and unless you have your own dedicated server or are running this off your own machine) then I doubt you can change it.

If you want to change it on your own machine then go to c:\windows or c:\winnt depending on your windows version, and open php.ini in notepad. Towards the bottom of the file you'll see the mail options (do a find for smtp is probably just as easy). use the tutorial on the page you found and insert your smtp server when you need to.

If this is online then contact your host and ask them if they have the mail function set up (or else run phpinfo on the said server and under one of the tables you'll see the mail option and see what it is set to).