Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/02/2012, 22:22
justfound
 
Fecha de Ingreso: febrero-2012
Mensajes: 7
Antigüedad: 12 años, 2 meses
Puntos: 0
me ayudais a pulir este formulario en php?

hola,

pues bien, tengo un formulario de contacto en php con la libreria de phpmailer.

el 50% ya lo tengo solucionado, enviar y recibir los mails los recibo y los envia perfectamente.

el problema esta en que al darle a enviar sin ningun dato puesto, envia lo envia en blanco.

y cuando falta un campo, no me dice los errores que deberia escribir. dice: "error inesperado" y arriba sale " mensaje enviado".

Las dos cosas a la vez!!!! esta descordinasimo


function valida_email($email) {
$re= '#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si';
return preg_match($re, $email);
}

function validarTelefono($phone)
{
$reg = "#^\(?\d{3}\)?[\s\.-]?\d{3}[\s\.-]?\d{4}$#";
return preg_match($reg, $phone);
}

$submit=$_POST['Submit'];
if($submit == Submit)
{
$status = "OK";
$email=$_POST['email'];
$message=$_POST['message'];
$subject=$_POST['subject'];
$name=$_POST['name'];
$phone=$_POST['phone'];
$title=$_POST['title'];
$otros2=$_POST['otros2'];

$msg="";
$msgerror="";
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);



if ( strlen($name) < 1 )
{
$msgerror .="* Nombre valido.<BR />";
$status= "NOTOK";
}


//if (!stristr($email,"@") OR !stristr($email,"."))
if(!valida_email($email))
{
$msgerror .="* Mail incorrecto.<BR />";
$status= "NOTOK";
}

//if ( strlen($phone) < 9 )
if(validarTelefono($phone))
{
$msgerror .="*Telefono compuesto por 9cifras.<BR />";
$status= "NOTOK";
}


if($title=="Opcion2")
{
$headers4="[email protected]";
}else if($title=="Opcion1"){
$headers4="[email protected]";
}else if($title=="error"){
$status="NOTOK";
$msgerror .="* Seleccione un titulo.<BR />";
}


if ( strlen($message) < 10 )
{
$msgerror .="* Mensaje minimo 10 caracteres.<BR/>";
$status= "NOTOK";
}


$body1="<html>
<head>
<p><font face=Tahoma, Helvetica, sans-serif size=2 color=#333333>
<strong>Formulari de Contacte Web:</strong></font><br>
<br><hr width=450px align=left><br>
<font face=Tahoma, Helvetica, sans-serif size=2>

<title>Formulario de Contacto Web</title>
</head>
<body>
<strong>Nombre:</strong> $name.<br>
<strong>Tel&eacute;fono:</strong> $phone.<br>
<strong>T&iacute;tulo:</strong> $title: $otros2.<br>
<strong>Email:</strong> $email.<br>
<strong>Mensaje:</strong> $message.</font></p>
</body>
</html> ";

require_once 'phpmailer/class.phpmailer.php';

$mail = new PHPMailer ();
$mail -> SetFrom ("[email protected]","[email protected]") ;
$mail -> AddAddress ("$email","$name");
$mail -> Subject = "$title: $otros2";
$mail -> IsHTML (true);
$mail -> IsSMTP();
$mail -> Host = 'mail.dominio.com';
$mail -> Port = 2626;
$mail -> SMTPDebug = 2;
$mail -> SMTPAuth = true;
$mail -> Username = '[email protected]';
$mail -> Password = 'password';
$mail -> MsgHTML(file_get_contents('www.dominio.com/archivos/recibido.html'));
if ($mail -> Send())
{
$msg=" Missatge enviat. Gràcies.";
}else{
$msgerror=" Error inesperado.";
}

$mail = new PHPMailer ();
$mail -> SetFrom ("[email protected]","[email protected]");
$mail -> AddAddress("$headers4");
$mail -> Subject = "$title: $otros2";
$mail -> IsHTML (true); // pones (true) en caso de usar formato HTML
$mail -> IsSMTP();
$mail -> Host = 'mail.dominio.com';
$mail -> Port = 2626;
$mail -> SMTPAuth = true;
$mail -> Username = '[email protected]';
$mail -> Password = 'password';
$mail -> MsgHTML($body1);
$mail -> Send();
}

cualquier dato sera bien recibido!!!

gracias, saludos!