I agree, and that error could then be taking place on mail (line breaks and tab characters don't belong in those parameters). There is a non-fatal error in logic on process_friend.php. Even if one or more of the names and/or one or more of the email addresses fails validation, as long as the CAPTCHA is passed, the email is sent. This (if my theory is correct) allows the invalid values to get passed to mail and cause the error.
You need a test for $status == 'is_ok'
in there somewhere, probably replacing the current CAPTCHA one, And the CAPTCHA test shouldn't surround the mail code, it should just be another test that adds (on failure) to the $write variable and as to whether or not the $status remains 'is_ok'.
Another issue is that, since it's never mentioned anywhere else:
Code:
if(empty($inputfields))
{ echo "<center><font face='Verdana' color='grey'><h3>Please note the following :-</h3><font face='Verdana' size='2' color=red>$write</font><center>";}
Is always true. But that content should only be echoed if there is a problem.
process_friend.php
PHP Code:
<?php
// never forget to start the session
session_start();
$_SESSION['form_data'] = $_POST;
?>
<html>
<head><title>Friend Link Processor</title></head>
<body>
<?php
//////////////VAIRABLES STORED HERE///////////////////////////////////////////////////////////////
$visitorcode=$_POST['visitorcode'];// VALIDATE CODE //
$status="is_ok";
$write="";
$m_name=$_POST['m_name']; $m_email=$_POST['m_email'];$f_name=$_POST['f_name'];$f_email=$_POST['f_email'];
///////////////////////////////////////COMMENCE FORM VALIDATION/////////////////////////////////////
/////////////////////STEP ONE VALIDATES THAT MY NAME IS ENTERED/////////////////////////////////////
if (strlen($m_name) <2 ) { $write.="Please enter your Name<BR />";$status="not_ok";}
////////////////////STEP TWO VALIDATES THAT MY CORRECT EMAIL ADDRESS IS USED////////////////////////
/////////////if (preg_match('/http:/', $notes))
if (!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $m_email))
{ $write.="Your email address is not correct!<BR />"; $status="not_ok";}
/////////////////STEP THREE VALIDATES THAT FRIENDS NAME ENTERED/////////////////////////////////////
if (strlen($f_name) <2 ) { $write.="Please enter your Friend's Name<BR />"; $status="not_ok";}
//////////////////STEP FOUR VALIDATES MY FRIENDS EMAIL///////////////////////////////////////////////
if (!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $f_email))
{ $write.="Your Friends email address is not correct!<BR />"; $status="not_ok";}
///////////////////STEP FIVE VALIDATES NUMBER OF EMAIL ADDRESSES USED/////////////////////////////////
if(substr_count($m_email,"@") > 1 or substr_count($f_email,"@") > 1)
{ $write.="Use only one email address please<BR />";$status="not_ok";}
if(empty($visitorcode))
{ $write.="Do not forget to fill out the <b>VALIDATE</b> code!<BR />";$status="not_ok";}
/////////////////Captcha Validation to block Spambots//////////////////////////////////////////////////////
if (md5($visitorcode) !== $_SESSION['image_random_value'])
{ $write.="<br /><font face='Verdana' size='2' color=blue>Your message was not sent because you entered the invalid letters - <b>$visitorcode</b><br />Please note that the letters are case sensitive. </font><BR />";
$status="not_ok"; }
if(!empty($write))
{ echo "<center><font face='Verdana' color='grey'><h3>Please note the following :-</h3><font face='Verdana' size='2' color=red>$write</font><center>";
echo '<br /><form action="form_friend.php"><input type="submit" value="Go Back to Form"></form>';
die();}
/* echo "<h2>Code $visitorcode valid </h2>\n"; */
///////////////////////////// INSTALL MESSAGE HERE ////////////////////////////////////////////////////
$header_message="Hi $f_name , \n\nYour friend $m_name invites you to visit Website at www.webitry.net \n\nYou can view a eCommerce Shopping Demonstration just to see how easy it is to sell online. \n\nIf you or any of your friends would like to sell online just contact the Webitry and discuss your requirement. They will be delighted to hear from you.\n\nHave a nice day!";
$body_message=$header_message."\n";
//// MAIL POSTING STARTS HERE /////////
$headers="";
//$headers="Content-Type: text/html; charset=iso-8859-1\n".$headers;
// Un comment the above line to send mail in html format
$headers4=$m_email; // Change this to change from address
$headers.="Reply-to: $headers4\n";
$headers.="From: $headers4\n";
$headers.="Errors-to: $headers4\n";
$subject="$m_name - Invitation to visit Website";
mail($f_email,$subject,$body_message,$headers);
///////////////////// END OF POSTING /////////////// & PRESENTING THANK YOU PAGE /////////////////////
echo "<center><font face='Verdana' size='3' color=green><br />Thank You, <br /><br />You sent a link for this Website to your friend $f_name. This is a great help to us. Your assistance is much appreciated.<br /><h3>The Webmaster.</h3></font></center>";
?>
</body>
</html>
The Form:
PHP Code:
<form method="post" action="process_friend.php">
<legend>Send Website Link to my Friend.</legend><br />
<label>My Name: </label><input type='text' id="textfield" name='m_name'
value='<?php if(isset($_SESSION['form_data']['m_name'])) { echo htmlspecialchars($_SESSION['form_data']['m_name']);}?>' /><br />
<label>My Email: </label><input type='text' id="textfield" name='m_email'
value='<?php if(isset($_SESSION['form_data']['m_email'])) { echo htmlspecialchars($_SESSION['form_data']['m_email']);}?>' /><br />
<label>Friend's Name: </label><input type='text' id="textfield" name='f_name'
value='<?php if(isset($_SESSION['form_data']['f_name'])) { echo htmlspecialchars($_SESSION['form_data']['f_name']);}?>' /><br />
<label>Friend's Email: </label><input type='text' id="textfield" name='f_email'
value='<?php if(isset($_SESSION['form_data']['f_email'])) { echo htmlspecialchars($_SESSION['form_data']['f_email']);}?>' /><br />
<hr>
<div>
<label>Validate Form:</label> <img src="randomImage.php"/>
<a href><img src="album/refresh.jpg" img style="border:0;" onclick="history.go()" alt="Get new Code" /></a>
<input type="text" name="visitorcode" size="5" />
</div>
<input type="submit" name="submitbutton" id="submitbutton" value="Send the Website Link to my Friend" />
</form>
Note: The form page should probably have (if it doesn't already):
PHP Code:
<?php
// never forget to start the session
session_start();
?>
at the beginning.
Bookmarks