Why my email sript is not running ? I tried with isset(), strlen(), also I have used it with other page i.e used script in other page and set action of form to that page url.
Variables are not empty. Below mentioned is the complete code of my script
<body>
<?
$to="sunjava11@gmail.com";
$name=$_POST["name"];
$email=$_POST["name2"];
$phone=$_POST["name3"];
$text=$_POST["message"];
$message="
Name: ".$name."\n
Email: ".$email."\n
Phone: ".$phone."\n
Message: ".$text."
";
function okay (){
if(!empty($name))
{
return true;
}
if(!empty($email))
{
return true;
}
if(!empty($text))
{
return true;
}
}
if (okay()==true)
{
$headers="From ".$name;
$subject="Contact Online at Al-Khidmat Punjab Website ";
mail($to,$subject,$message,$headers);
}
else
{
echo "mail not sent";
}
?>
<form id="form1" name="form1" method="post" action="/subpage-recv">
<table width="618" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="232" class="leftCol">Name</td>
<td width="370"><label for="name"></label>
<input type="text" name="name" id="name" class="input" /></td>
</tr>
<tr>
<td class="leftCol">Email</td>
<td class="rightCol"><input type="text" name="name2" id="name2" class="input" /></td>
</tr>
<tr>
<td class="leftCol">Phone Number <span class="smalltext">(optional)</span></td>
<td class="rightCol"><input type="text" name="name3" id="name3" class="input" /></td>
</tr>
<tr>
<td class="leftCol" style="border:none">Message</td>
<td class="rightCol" style="border:none"><label for="message"></label>
<textarea name="message" id="message" cols="45" rows="5" ></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Send" id="send"></td>
</tr>
</table>
</form>
</body>
The global variables are not visible inside okay() .
You may use the global-keyword or the $GLOBALS-array to be able to access them.
http://php.net/manual/en/language.variables.scope.php