homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Tell A Friend PHP Script.
Halt sending email, if visitor did not fill in form (help)

10+ Year Member

Msg#: 11132 posted 8:31 pm on Dec 21, 2005 (gmt 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>



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

Msg#: 11132 posted 11:24 pm on Dec 21, 2005 (gmt 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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved