Foros del Web » Programando para Internet » PHP »

Cual es el mejor formulario de PHP con algun Captcha?

Estas en el tema de Cual es el mejor formulario de PHP con algun Captcha? en el foro de PHP en Foros del Web. Buenos dias, amigos me ando peleando con los formularios , que opinan del mio? No me llegan a veces los emails, y ademas a veces ...
  #1 (permalink)  
Antiguo 13/07/2011, 10:26
 
Fecha de Ingreso: enero-2009
Ubicación: Tijuana
Mensajes: 80
Antigüedad: 15 años, 3 meses
Puntos: 2
Cual es el mejor formulario de PHP con algun Captcha?

Buenos dias, amigos me ando peleando con los formularios , que opinan del mio? No me llegan a veces los emails, y ademas a veces me llega SPAM, entonces alguna sugerencia de un codigo PHP y Captcha juntos para su proteccion?


EMAIL.PHP :

Código PHP:
<?php
session_start
();
if(isset(
$_POST["Code"])) {
    if((
$_SESSION['captcha_code'] == $_POST['Code']) && (!empty($_SESSION['captcha_code'])) ) {
        
//Passed!
        
        
$captcha_msg="Thank you";
        
$admin'[email protected]'//
  
$subject'Titulo de Subject';
  
$message'Message to '.$admin.' from '.$email.":\n\n";

  foreach(
$HTTP_POST_VARS as $name=> $value) {
    
$message.= "$name: $value\n";
  }

$message WORDWRAP($message,75,"\n");

  
mail($admin$subjectSTRIPSLASHES$message ) , "From: $email");

header('Location: http://'.getenv('HTTP_HOST').'/thanks.php');
        
    }else{
        
// Not passed 8-(
        
$captcha_msg="<font color=\"ff0000\">"."Invalid Code"."</font>";
        
//$captcha_msg="invalid code";
        
if(isset($_POST["MM_insert"])){
              unset(
$_POST["MM_insert"]);
        }
        if(isset(
$_POST["MM_update"])){
            unset(
$_POST["MM_update"]);
        }
    }
}
class 
CaptchaImage {
    var 
$font "verdana.ttf";
    function 
hex_to_dec($hexcolor){
    
//convert hex hex values to decimal ones
    
$dec_color=array('r'=>hexdec(substr($hexcolor,0,2)),'g'=>hexdec(substr($hexcolor,2,2)),'b'=>hexdec(substr($hexcolor,4,2)));
    return 
$dec_color;
    }
    function 
generateCode($characters) {
        
/* list all possible characters, similar looking characters and vowels have been removed */
        
$possible '23456789bcdfghjkmnpqrstvwxyz'
        
$code '';
        
$i 0;
        while (
$i $characters) { 
            
$code .= substr($possiblemt_rand(0strlen($possible)-1), 1);
            
$i++;
        }
        return 
$code;
    }
    function 
CaptchaImage($width='150',$height='30',$characters='6',$hex_bg_color='FFFFFF',$hex_text_color="FF0000",$hex_noise_color="CC0000"$img_file='captcha.jpg') {
        
$rgb_bg_color=$this->hex_to_dec($hex_bg_color);
        
$rgb_text_color=$this->hex_to_dec($hex_text_color);
        
$rgb_noise_color=$this->hex_to_dec($hex_noise_color);
        
$code $this->generateCode($characters);
        
/* font size will be 60% of the image height */
        
$font_size $height 0.60;
        
$image = @imagecreate($width$height) or die('Cannot Initialize new GD image stream');
        
/* set the colours */
        
$background_color imagecolorallocate($image$rgb_bg_color['r'], $rgb_bg_color['g'],$rgb_bg_color['b']);
        
$text_color imagecolorallocate($image$rgb_text_color['r'], $rgb_text_color['g'],$rgb_text_color['b']);
        
$noise_color imagecolorallocate($image$rgb_noise_color['r'], $rgb_noise_color['g'],$rgb_noise_color['b']);
        
/* generate random dots in background */
        
for( $i=0$i<($width*$height)/3$i++ ) {
            
imagefilledellipse($imagemt_rand(0,$width), mt_rand(0,$height), 11$noise_color);
        }
        
/* generate random lines in background */
        
for( $i=0$i<($width*$height)/150$i++ ) {
            
imageline($imagemt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        }
        
/* create textbox and add text */
        
$textbox imagettfbbox($font_size0$this->font$code);
        
$x = ($width $textbox[4])/2;
        
$y = ($height $textbox[5])/2;
        
imagettftext($image$font_size0$x$y$text_color$this->font $code);
        
/* save the image */
        
imagejpeg($image,$img_file);
        
imagedestroy($image);
        echo 
"<img src=\"$img_file?".time()."\" width=\"$width\" height=\"$height\" alt=\"security code\" id=\"captchaImg\">";
        
$_SESSION['captcha_code'] = $code;
    }

}
?>

Formulario:

Código HTML:
<form action="email.php" method="post" name="forma" id="forma">
                  <table width="489" border="0" align="center" cellpadding="0" cellspacing="0" class="form" id="form">
                    <tr>
                      <td colspan="2"><p>
                        <label>* denotes a required field<br />
                          <br />
                        </label>
                      </p></td>
                    </tr>
                    <tr>
                      <td width="220"><p>
                        <label></label>
                        <label>First Name: </label>
                        <br />
                      </p></td>
                      <td width="170"><p>
                        <input name="nombre" type="text" class="campo" id="nombre" size="35" />
                      </p></td>
                    </tr>
                    <tr>
                      <td><p>
                        <label>Last Name: </label>
                      </p></td>
                      <td><p>
                        <input name="contact_last_name" type="text" size="35" />
                      </p></td>
                    </tr>
                    <tr>
                      <td><p>
                        <label>Address me as: </label>
                        <br />
                        <label></label>
                      </p></td>
                      <td><p>
                        <input name="contact_greeting" type="text" size="35" />
                      </p></td>
                    </tr>
                    <tr>
                      <td><p>
                        <label>Email: </label>
                        <br />
                        <label></label>
                      </p></td>
                      <td><p>
                        <input name="email" type="text" class="campo" id="email" size="35" />
                      </p></td>
                    </tr>
                    <tr>
                      <td><p>
                        <label>Phone: </label>
                      </p></td>
                      <td><p>
                        <input name="contact_home_phone" type="text" size="35" />
                      </p></td>
                    </tr>
                    <tr>
                      <td><p>
                        <label>How did you hear about our practice? </label>
                        <br />
                        <label></label>
                      </p></td>
                      <td><p>
                        <select name="how_did_you_hear_about_our_practice">
                          <option selected="selected">Choose one...</option>
                          <option value="Staff Member">Staff Member </option>
                          <option value="Advertisement">Advertisement</option>
                          <option value="Yellow Pages">Yellow Pages</option>
                          <option value="Other">Other</option>
                        </select>
                      </p></td>
                    </tr>
                    <tr>
                      <td><p>
                        <label>How did you find our website? </label>
                      </p></td>
                      <td><p>
                        <select name="how_did_you_find_our_website">
                          <option selected="selected">Choose one...</option>
                          <option value="Search Engine">Search Engine</option>
                          <option value="Advertisement">Advertisement</option>
                          <option value="A friend">A friend</option>
                          <option value="Unknown">Unknown</option>
                        </select>
                      </p></td>
                    </tr>
                    <tr>
                      <td><p>Comments: </p></td>
                      <td><p>
                        <textarea name="contact_comment" rows="7" cols="18"></textarea>
                      </p></td>
                    </tr>
                    <tr>
                      <td colspan="2"><div align="center">
                        <p>* For your security, please fill the code below:<br />
                          <?php $captcha = new CaptchaImage(150,50,5,'547d93','000000','0066CC');?>
                          <br />
                          Code
                          <input type="text" name="Code" id="Code" />
                        </p>
                      </div>
                        <p>
                          </label>
                          <?php echo $captcha_msg ?>&nbsp;&nbsp;</p></td>
                    </tr>
                    <tr>
                      <td><p>&nbsp;</p></td>
                      <td><p>
                        <input name="button2" type="submit" class="form" id="button2" value="Send" />
                      </p></td>
                    </tr>
                  </table>
                </form> 
  #2 (permalink)  
Antiguo 13/07/2011, 10:28
Avatar de iviamontes  
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 13 años, 3 meses
Puntos: 209
Respuesta: Cual es el mejor formulario de PHP con algun Captcha?

http://www.google.com/recaptcha
__________________
aconcaguaestudio.com
  #3 (permalink)  
Antiguo 13/07/2011, 10:43
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Cual es el mejor formulario de PHP con algun Captcha?

Existen muchos ejemplos en internet, entre uno de ellos esta el de zend framework.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #4 (permalink)  
Antiguo 13/07/2011, 10:53
 
Fecha de Ingreso: enero-2009
Ubicación: Tijuana
Mensajes: 80
Antigüedad: 15 años, 3 meses
Puntos: 2
Respuesta: Cual es el mejor formulario de PHP con algun Captcha?

Cita:
Iniciado por iviamontes Ver Mensaje
Amigo ya intente el RECAPTCHA y no me lo vas a creer pero llega SPAM
  #5 (permalink)  
Antiguo 13/07/2011, 10:56
Avatar de iviamontes  
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 13 años, 3 meses
Puntos: 209
Respuesta: Cual es el mejor formulario de PHP con algun Captcha?

y tienes asegurado que no puedan insertarte datos desde webs externas ???
__________________
aconcaguaestudio.com
  #6 (permalink)  
Antiguo 13/07/2011, 10:59
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Cual es el mejor formulario de PHP con algun Captcha?

¿Cómo lo haz hecho? Porque si llega spam es porque algo estás haciendo mal o lo que usaste está mal.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #7 (permalink)  
Antiguo 13/07/2011, 11:20
 
Fecha de Ingreso: enero-2009
Ubicación: Tijuana
Mensajes: 80
Antigüedad: 15 años, 3 meses
Puntos: 2
Respuesta: Cual es el mejor formulario de PHP con algun Captcha?

Cita:
Iniciado por abimaelrc Ver Mensaje
¿Cómo lo haz hecho? Porque si llega spam es porque algo estás haciendo mal o lo que usaste está mal.
Este era mi formulario:
claro ya viene incluido las librerias.

A ver que opinas:

mail.php

Código HTML:
<form id="form1" name="form1" method="post" action="thanksre.php"> 
<table width="450" border="0" align="center" cellpadding="0" cellspacing="0" class="text-panel"> 
<tr>
  <td width="139">Name:</td>
  <td width="10">&nbsp;</td>
  <td width="305"><label for="name"></label>
    <input type="text" name="name" id="name"></td>
</tr>
<tr>
  <td>Address:</td>
  <td>&nbsp;</td>
  <td><label for="address"></label>
    <input type="text" name="address" id="address"></td>
</tr>
<tr>
  <td>City/State</td>
  <td>&nbsp;</td>
  <td><label for="city_state"></label>
    <input type="text" name="city_state" id="city_state" /></td>
</tr>
<tr>
  <td>Phone:</td>
  <td>&nbsp;</td>
  <td><label for="phone"></label>
    <input type="text" name="phone" id="phone"></td>
</tr>
<tr>
  <td>Facial Procedures:</td>
  <td>&nbsp;</td>
  <td><label for="facial_procedures"></label>
    <label for="facial_procedures"></label>
    <textarea name="facial_procedures" id="facial_procedures" cols="45" rows="5"></textarea></td>
</tr>
<tr>
  <td>Breast Procedures</td>
  <td>&nbsp;</td>
  <td><label for="breast_procedures"></label>
    <textarea name="breast_procedures" id="breast_procedures" cols="45" rows="5"></textarea></td>
</tr>
<tr>
  <td>Body Procedures</td>
  <td>&nbsp;</td>
  <td><label for="body_procedures"></label>
    <textarea name="body_procedures" id="body_procedures" cols="45" rows="5"></textarea></td>
</tr>
<tr>
  <td>Email:</td>
  <td>&nbsp;</td>
  <td><label for="email"></label>
    <input type="text" name="email" id="email"></td>
</tr> 
<tr> 
  <td>&nbsp;</td>
  <td>&nbsp;</td> 
  <td><?php 
// Require reCAPTCHA lib 
require_once('recaptchalib.php'); 
// Your public key you get this from signup page 
$publickey = "6Le5_MISAAAAAKavlin2lQ-3OTYVkBDAyXYCprbH"; 
echo recaptcha_get_html($publickey); 
?></td> 
</tr> 
<tr>
  <td>Comments:</td>
  <td>&nbsp;</td>
  <td><label for="comments"></label>
    <textarea name="comments" id="comments" cols="45" rows="5"></textarea></td>
</tr>
<tr> 
<td>&nbsp;</td>
<td>&nbsp;</td> 
<td><input type="submit" name="submit" id="submit" value="Submit" /></td> 
</tr> 
</table> 
</form> 
thanksre.php

Código PHP:
<?php 
// Check if submit button has been submitted 
if (isset($_POST['submit'])){ 
// Include reCAPTCHA lib 
require_once('recaptchalib.php'); 
// Your private key goes here between quotes 
$privatekey "6Le5_MISAAAAAKe-Nd6MRZEQ44XOYvm9CHWrZ8EX"
$resp recaptcha_check_answer ($privatekey
$_SERVER["REMOTE_ADDR"], 
$_POST["recaptcha_challenge_field"], 
$_POST["recaptcha_response_field"]); 
if (!
$resp->is_valid) { 
// What happens when the CAPTCHA was entered incorrectly 
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." 
"(reCAPTCHA said: " $resp->error ")"); 
} else { 
// Put here what would happen if words are entered correctly 
$name $_POST['name'];
           
$address $_POST['address'];
           
$city_state $_POST['city_state'];
           
$phone $_POST['phone'];
           
$facial_procedures $_POST['facial_procedures'];
           
$breast_procedures $_POST['breast_procedures'];
           
$body_procedures $_POST['body_procedures'];
           
$email $_POST['email'];
           
$comments $_POST['comments'];
                      
                     
            
//Estoy recibiendo el formulario, compongo el cuerpo 
            
$cuerpo .= "Name:    " $name "\n"
            
$cuerpo .= "Address: " $address "\n";
            
$cuerpo .= "City/State: " $city_state "\n";
            
$cuerpo .= "Facial Procedures: " $facial_procedures "\n";
            
$cuerpo .= "Breast Procedures: " $breast_procedures "\n";
            
$cuerpo .= "Body Procedures: " $body_procedures "\n";
            
$cuerpo .= "Phone:      " $phone "\n"
            
$cuerpo .= "Email:       " $email "\n"
            
$cuerpo .= "Comments: " $comments "\n";  
            
            
            
//$cuerpo .= 'Archivo: <a href="'.$url.'images/'.$userfile.'">'.$userfile.'</a>';
        
            //mando el correo...   
            
mail("[email protected]","Titulo",$cuerpo);  //
            
header('Location: http://'.getenv('HTTP_HOST').'/thanksre.php');
//echo "You have entered reCAPTCHA words correctly, your entered text is: ".$_POST['text']."";


?>
  #8 (permalink)  
Antiguo 13/07/2011, 12:04
 
Fecha de Ingreso: enero-2009
Ubicación: Tijuana
Mensajes: 80
Antigüedad: 15 años, 3 meses
Puntos: 2
Respuesta: Cual es el mejor formulario de PHP con algun Captcha?

O que tal este formulario: como le podria asignar el RECAPTCHA? y tambien para copia oculta? Espero no molestarlos mucho amigos en verdad necesito su ayuda

gracias.:

CONTACT.PHP

Código HTML:
<form action="thanks.php" method="post" enctype="multipart/form-data" onsubmit="MM_validateForm('email','','R','telephone','','R');return document.MM_returnValue">
                <p><span class="text-panel">First and Last Name:</span><br />
                  <input class="campo" type="text" name="nombre" />
                </p>
                <p><span class="text-panel">Email  Address</span><br />
                  <input name="email" type="text" class="campo" id="email" />
                </p>
                <p><span class="text-panel">Telephone</span><br />
                  <input type="text" name="telephone" class="campo" id="telephone" />
                </p>
                <p><span class="text-panel">Comments:</span><br />
                  <textarea name="comentario" class="com"></textarea>
                </p>
                <p>
                  <input class="boton" type="submit" name="enviar" value="Send" />
                </p>
              </form> 


THANKS.PHP

Código PHP:
<?php

$direccion_envio
='[email protected]';                         //la direccion a la que se enviara el email.
$url='http://www.dominioo.com/thanks.php';         //la URL donde esta publicado el formulario. SIN la barra al final

?>


<?php

if (isset ($_POST['enviar'])) {

require(
"class.phpmailer.php");

$mail = new PHPMailer();

//recogemos las variables y configuramos PHPMailer
$mail->From $_POST['email'];
$mail->FromName $_POST['nombre'];
$mail->AddAddress($direccion_envio); 
$mail->Subject "Cosmetic Surgery in Mexico  - English";
$mail->AddReplyTo($_POST['email'],$_POST['nombre']);
$mail->IsHTML(true);                              
$telephone=$_POST['telephone'];
$comentario=$_POST['comentario'];
$nombre1=$_POST['nombre'];
$email1=$_POST['email'];

//comprobamos si se adjunto un archivo, y si su tamano es menor al permitido
if (isset($_FILES['archivo']['tmp_name'])) {
$aleatorio rand(); 
$nuevonombre=$aleatorio.'-'.$_FILES['archivo']['name'];
}

// copiamos el archivo en el servidor
copy($_FILES['archivo']['tmp_name'],'archivos/'.$nuevonombre);

//armamos el html
$contenido '<html><body>';
$contenido .= '<h2>Titulo</h2>';
$contenido .= '<p>Send '.date("d M Y").'</p>';
$contenido .= '<hr />';
$contenido .= '<p>Full Name: <strong>'.$nombre1.'</strong>';
$contenido .= '<p>Email: <strong>'.$email1.'</strong>';
$contenido .= '<p>Telephone: <strong>'.$telephone.'</strong>';
$contenido .= '<p>Comments: <strong>'.$comentario.'</strong>';
$contenido .= '<hr />';
$contenido .= '</body></html>';

$mail->Body    $contenido;
$mail->AddAttachment('archivos/'.$nuevonombre.''$nuevonombre);  // optional name
//  enviamos el mail

$mail->Send();
 
Gracias por Contactarnos</div>;

}
?>

Etiquetas: formulario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:50.