Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Tell A Friend PHP Script.

Halt sending email, if visitor did not fill in form (help)

8:31 pm on Dec 21, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 21, 2004
votes: 0

Hi All,

I am using the "Tell A Friend" script below. It works well. My problem is that the script will send an email if the form is filled in or not (upon pressing the submit button.) How can I make sure the visitor fills in the form? Thanks in advance..


Thank You : <?php echo $visitor?> ( <?php echo $visitormail?> ) <br>
For sending : <a href="<?php echo $urlis?>"> <?php echo $sitename?>
</a> (link)<br>
To: <?php echo $friend?> (<?php echo $friendmail?>)
<a href="<?php echo $redirectlink?>"> Next Page </a>
<HR width="80%">

$ip = getenv("REMOTE_ADDR");
if (!isset($visitormail) !isset($friendmail))
echo "<font size=6>You Goofed</font> $ip" ;
$todayis = date("l, F j, Y, g:i a") ;
$notes = stripcslashes($notes); $messageis = " $todayis [EST] \n
Your Friend: $visitor ($visitormail)\n
Sent this URL: $sitename ($urlis) \n
To: $friend $friendmail \n
With These Comments: $notes \n
Generated by Tell A Friend () ";

$messageme = $ip . " " . $messageis;

$from = "From: fromemailhere\r\n";

mail("youremailHERE", $sitename, $messageme, $from);
if ($friendmail!= "")
mail($friendmail, $sitename, $messageis, $from);
if ($visitormail!= "")
mail($visitormail, $sitename, $messageis, $from);

<table height="235">
<tr><td colspan="2" class="warning">&nbsp;&nbsp;</td></tr>
<tr><td>Your Name:</td><td>
<input type="text" name="visitor" size="30"/></td></tr>
<tr><td>Your E-mail:</td><td>
<input type="text" name="visitormail" maxlength="50" size="30"/></td></tr>
<tr><td>Friend's Name:</td><td>
<input type="text" name="friend" size="30"/></td></tr>
<tr><td>Friend's E-mail:</td><td>
<input type="text" name="friendmail" size="30"/></td></tr>
<textarea name="notes" rows="5" cols="30">I thought you might find this website interesting. Please click on the link provided to visit the site.</textarea></td></tr>
<tr align="left" valign="top">
<td align="center">
<input type="image" name="submit" src="images/blue_submit.gif" border="0" alt="submit" /></td></tr></table></td></tr></table>

11:24 pm on Dec 21, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
votes: 0

Hi Senmar50,

You need to kill the script if certain fields are not filled in when you process. Something like:

if (isset($_POST['submit']))

//Assign array
$error_string = array();

//Do check
if (trim($_POST['visitor'])=='')
$error_string[] = 'Please fill out your name!';
if (trim($_POST['visitormail'])=='')
$error_string[] = 'Please include your e-mail address!';
if (trim($_POST['friend'])=='')
$error_string[] = 'Please fill out your friends name!';
if (trim($_POST['friendmail'])=='')
$error_string[] = 'Please include your friends e-mail address!';

//Are any errors present?
if ($error_string)

echo "Please correct the following:<br><br>";

foreach ($error_string as $errors)
echo $errors."<br>";

//Ok, complete processing.

You might also want to check for valid e-mail addresses using a regex command.



Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members