Nie znam się na php dlatego prosiłbym o pomoc.
Dostaje sporo SPAMU przez formularz kontaktowy, które są wysyłane przez boty.
Obecnie korzystam z :
contactscript.php
KOD
<?php
// VALUES FROM THE FORM
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['msg'];
// ERROR & SECURITY CHECKS
if ( ( !$email ) ||
( strlen($_POST['email']) > 200 ) ||
( !preg_match("#^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$#", $email) )
)
{
print "Error: Invalid E-Mail Address";
exit;
}
if ( ( !$name ) ||
( strlen($name) > 100 ) ||
( preg_match("/[:=@\<\>]/", $name) )
)
{
print "Error: Invalid Name";
exit;
}
if ( preg_match("#cc:#i", $message, $matches) )
{
print "Error: Found Invalid Header Field";
exit;
}
if ( !$message )
{
print "Error: No Message";
exit;
}
if (eregi("\r",$email) || eregi("\n",$email)){
print "Error: Invalid E-Mail Address";
exit;
}
if (FALSE) {
print "Error: You cannot send to an email address on the same domain.";
exit;
}
// CREATE THE EMAIL
$headers = "Content-Type: text/plain; charset=iso-8859-1\n";
$headers .= "From: $name <$email>\n";
$recipient = "mojmail@gmail.com";
$subject = "Mail z strony";
$message = wordwrap($message, 1024);
// SEND THE EMAIL TO YOU
mail($recipient, $subject, $message, $headers);
// REDIRECT TO THE THANKS PAGE
header("location: thanks.php");
?>
// VALUES FROM THE FORM
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['msg'];
// ERROR & SECURITY CHECKS
if ( ( !$email ) ||
( strlen($_POST['email']) > 200 ) ||
( !preg_match("#^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$#", $email) )
)
{
print "Error: Invalid E-Mail Address";
exit;
}
if ( ( !$name ) ||
( strlen($name) > 100 ) ||
( preg_match("/[:=@\<\>]/", $name) )
)
{
print "Error: Invalid Name";
exit;
}
if ( preg_match("#cc:#i", $message, $matches) )
{
print "Error: Found Invalid Header Field";
exit;
}
if ( !$message )
{
print "Error: No Message";
exit;
}
if (eregi("\r",$email) || eregi("\n",$email)){
print "Error: Invalid E-Mail Address";
exit;
}
if (FALSE) {
print "Error: You cannot send to an email address on the same domain.";
exit;
}
// CREATE THE EMAIL
$headers = "Content-Type: text/plain; charset=iso-8859-1\n";
$headers .= "From: $name <$email>\n";
$recipient = "mojmail@gmail.com";
$subject = "Mail z strony";
$message = wordwrap($message, 1024);
// SEND THE EMAIL TO YOU
mail($recipient, $subject, $message, $headers);
// REDIRECT TO THE THANKS PAGE
header("location: thanks.php");
?>
oraz kodu w kontakt.html
KOD
<form name="form" method="post" action="contactform/contactscript.php">
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="200" valign="top" align="right">Imię i nazwisko: </td>
<td width="200" valign="top" align="left">
<input type="text" name="name" size="25" maxlength="200" />
</td>
</tr><tr>
<td width="200" valign="top" align="right">Twój Email: </td>
<td width="200" valign="top" align="left">
<input type="text" name="email" size="25" maxlength="100" />
</td>
</tr><tr>
<td width="200" valign="top" align="right">Treść wiadomości: </td>
<td width="200" valign="top" align="left">
<textarea name="msg" cols="25" rows="4"></textarea>
</td>
</tr><tr>
<td width="200" valign="top"> </td>
<td width="200" valign="top" align="left">
<input type="reset" name="Reset" value="Wyczyść" />
<input type="submit" name="Submit" value="Wyślij" />
</td>
</tr>
</table>
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="200" valign="top" align="right">Imię i nazwisko: </td>
<td width="200" valign="top" align="left">
<input type="text" name="name" size="25" maxlength="200" />
</td>
</tr><tr>
<td width="200" valign="top" align="right">Twój Email: </td>
<td width="200" valign="top" align="left">
<input type="text" name="email" size="25" maxlength="100" />
</td>
</tr><tr>
<td width="200" valign="top" align="right">Treść wiadomości: </td>
<td width="200" valign="top" align="left">
<textarea name="msg" cols="25" rows="4"></textarea>
</td>
</tr><tr>
<td width="200" valign="top"> </td>
<td width="200" valign="top" align="left">
<input type="reset" name="Reset" value="Wyczyść" />
<input type="submit" name="Submit" value="Wyślij" />
</td>
</tr>
</table>
Znalazłem w Google, taki skrypt :
captcha.php
KOD
<?
session_start();
$pool = '0123456789abcdefghijklmnopqrstuvwxyz';
$img_width = 120;
$img_height = 30;
$str = '';
for ($i = 0; $i < 7; $i++){
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
$string = $str;
$_SESSION['captcha'] = $string;
$im = imagecreate($img_width, $img_height);
$bg_color = imagecolorallocate($im,163,163,163);
$font_color = imagecolorallocate($im,252,252,252);
$grid_color = imagecolorallocate($im,31,0,0);
$border_color = imagecolorallocate ($im, 174, 174, 174);
imagefill($im,1,1,$bg_color);
for($i=0; $i<1600; $i++){
$rand1 = rand(0,$img_width);
$rand2 = rand(0,$img_height);
imageline($im, $rand1, $rand2, $rand1, $rand2, $grid_color);
}
$x = rand(5, $img_width/(7/2));
imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);
for($a=0; $a < 7; $a++){
imagestring($im, 5, $x, rand(6 , $img_height/5), substr($string, $a, 1), $font_color);
$x += (5*2); #odstęp
}
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
?>
session_start();
$pool = '0123456789abcdefghijklmnopqrstuvwxyz';
$img_width = 120;
$img_height = 30;
$str = '';
for ($i = 0; $i < 7; $i++){
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
$string = $str;
$_SESSION['captcha'] = $string;
$im = imagecreate($img_width, $img_height);
$bg_color = imagecolorallocate($im,163,163,163);
$font_color = imagecolorallocate($im,252,252,252);
$grid_color = imagecolorallocate($im,31,0,0);
$border_color = imagecolorallocate ($im, 174, 174, 174);
imagefill($im,1,1,$bg_color);
for($i=0; $i<1600; $i++){
$rand1 = rand(0,$img_width);
$rand2 = rand(0,$img_height);
imageline($im, $rand1, $rand2, $rand1, $rand2, $grid_color);
}
$x = rand(5, $img_width/(7/2));
imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);
for($a=0; $a < 7; $a++){
imagestring($im, 5, $x, rand(6 , $img_height/5), substr($string, $a, 1), $font_color);
$x += (5*2); #odstęp
}
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
?>
+index.php
KOD
<?
session_start();
if($_POST['captcha'] != $_SESSION['captcha']){
echo '<font style="color:#c03400;">Niepoprawnie przepisałeś kod z obrazka</font><br>';
}else{
#coś robisz :)
}
?>
session_start();
if($_POST['captcha'] != $_SESSION['captcha']){
echo '<font style="color:#c03400;">Niepoprawnie przepisałeś kod z obrazka</font><br>';
}else{
#coś robisz :)
}
?>
Próbowałem je połączyć, bez skutku.Pierwszy wysyła maila, ale nie wyświetla tokenu.Drugi za to wymaga tokenu, ale nie wysyła maila - nie znalazłem w nim też miejsca, w którym mógłbym wpisać adres maila, na który ma wysyłać pocztę.
Byłbym wdzięczny za pomoc osobie, która powie co mam zmienić w jednym z nich, aby w trakcie wysyłania wiadomości przez formularz kontaktowy, trzeba było przepisać token.