I have a mail form on my HTML that calls a PHP. When I click Submit, It redirects to the PHP and shows various alerts about the form.
I want it not to redirect to the PHP and show alerts on HTML. I tried to redirect back from PHP but in that case it didn't show any alerts.
I couldn't manage to do that. I've read may similar posts but they didn't help.
Can anyone help?
HTML Form:
<form method="post" action="sendmail.php">
<input name="id" type="hidden" value="1775">
<table cellpadding="10px" border="0">
<tr>
<td align="right"><iletisimmetni>ad soyad :</iletisimmetni></td>
<td><input class="yuvarlak" name="sender_name" type="text"></td>
</tr>
<tr>
<td align="right"><iletisimmetni>e-posta :</iletisimmetni></td>
<td><input class="yuvarlak" name="sender_email" type="email"></td>
</tr>
<tr>
<td align="right"><iletisimmetni>konu :</iletisimmetni></td>
<td><input class="yuvarlak" name="subject" type="text"></td>
</tr>
<tr>
<td align="right" valign="top"><iletisimmetni>mesaj :</iletisimmetni></td>
<td><textarea class="yuvarlak" rows="10" cols="40" name="message"
onkeyup="textLimit(this, 250);"></textarea></td>
</tr>
<tr>
<td colspan="2" align="right"><input class="urunbutton" value="Gönder" name="send"
type="submit" id="send"></td>
</tr>
</table>
</form>
Here is the PHP:
<?php
function spamcheck($field)
{
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['sender_email']) && !empty($_REQUEST['sender_name']) &&
!empty($_REQUEST['subject']) && !empty($_REQUEST['message']))
{
$mailcheck = spamcheck($_REQUEST['sender_email']);
if ($mailcheck==FALSE)
{
echo "<script>alert('Lütfen geçerli bir e-posta adresi girin.')</script>";
// $URL="http://pantuff.com/testing/iletisim.html";
// header ("Location: $URL");
}
else
{//send email
$sender_name = $_REQUEST['sender_name'] ;
$sender_email = $_REQUEST['sender_email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$headers = "From: ".$sender_name." <".$sender_email.">
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=utf-8
";
mail("info@pantuff.com", "$subject", "$message" . " " . "$sender_name", $headers);
echo "<script>alert('Mesajınız alınmıştır. Teşekkür ederiz.')</script>";
// $URL="http://pantuff.com/testing/iletisim.html";
// header ("Location: $URL");
}
}
else
{
echo "<script>alert('Lütfen tüm alanları doldurun.')</script>";
// $URL="http://pantuff.com/testing/iletisim.html";
// header ("Location: $URL");
}
?>
Thanks.