Buongiorno a tutti avrei un problema con php riguardo l'inserimento del captcha in un modulo per mail, ho scaricato già tutto ma dalle varie prove che ho fatto non sono riuscito ad ottenere qualcosa che funzioni, spero di non disturbare eccessivamente ed incontrare qualche benintenzionato a darmi una mano.
Il form mail è composto di due file nel quale vorrei inserire lo script captcha, per quanto già ne so andrebbe inserito nel punto in cui vorrei fosse visibile ma non mi funziona, potreste dare un'occhio al codice per favore
questa è la prima pagina del modulo per mail: send.php
Codice PHP:
<?php $receiverMail = "your@email.com"; $name = ltrim(rtrim(strip_tags(stripslashes($_POST['name'])))); $email = ltrim(rtrim(strip_tags(stripslashes($_POST['email'])))); $subject = ltrim(rtrim(strip_tags(stripslashes($_POST['subject'])))); $msg = ltrim(rtrim(strip_tags($_POST['msg']))); $ip = getenv("REMOTE_ADDR"); $msgformat = "From: $name ($ip)\nEmail: $email\n\n$msg"; // VALIDATION if(empty($name) || empty($email) || empty($subject) || empty($msg)) { echo "<h3>The email was not sent</h3>
Please fill all the required fields</p>"; } elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { echo "<h3>The email was not sent</h3>
The email address is invalid</p>"; } else { mail($receiverMail, $subject, $msgformat, "From: $name <$email>"); echo "<h3>The email has been sent!</h3>
I will get back to you as soon as possible.</p>"; } ?>
seconda pagina del modulo mail: contact.php
Codice PHP:
<form method="post" action="send.php"> Name:
<input name="name" type="text" size="30" maxlength="40" />
Email:
<input name="email" type="text" size="30" maxlength="40" />
Subject:
<input name="subject" type="text" size="30" maxlength="40" />
Message:
<textarea name="msg" cols="50" rows="6"></textarea>
<input type="reset" value="Reset" /><input type="submit" value="Send" /> </form>
questo è lo script per il captcha (captcha.php)
Codice PHP:
< ?php header("Content-type: image/png"); $x = 200; $y = 75; $code = substr($_GET['code'],0,9); $space = $x / (strlen($code)+1); $img = imagecreatetruecolor($x,$y); $bg = imagecolorallocate($img,255,255,255); $border = imagecolorallocate($img,0,0,0); $colors[] = imagecolorallocate($img,128,64,192); $colors[] = imagecolorallocate($img,192,64,128); $colors[] = imagecolorallocate($img,108,192,64); imagefilledrectangle($img,1,1,$x-2,$y-2,$bg); imagerectangle($img,0,0,$x-1,$y-2,$border); for ($i=0; $i< strlen ($code); $i++) { $color = $colors[$i % count($colors)]; imagettftext($img,28+rand(0,8),-20+rand(0,40),($i+0.3)*$space,50+rand(0,10),$color,'alba.ttf',$code{$i}); } for($i=0;$i<400;$i++) { $x1 = rand(3,$x-3); $y1 = rand(3,$y-3); $x2 = $x1-2-rand(0,8); $y2 = $y1-2-rand(0,8); imageline($img,$x1,$y1,$x2,$y2,$colors[rand(0,count($colors)-1)]); } imagepng($img); ?>
ringrazio anticipatamente chi mi riuscisse ad effettuare il copia/incolla nella maniera corretta