Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/02/2012, 13:28
ekisdedede
 
Fecha de Ingreso: febrero-2010
Mensajes: 113
Antigüedad: 14 años, 2 meses
Puntos: 5
Respuesta: Como validar en PHPMailer

Ya lo tengo validado antes, pero no lo detecta!

Este es el código completo:

Código PHP:
Ver original
  1. function valida_email($email) {
  2. $re= '#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si';
  3. return preg_match($re, $email);
  4. }
  5.  
  6. function validarTelefono($phone)
  7. {
  8. $reg = "#^\(?\d{3}\)?[\s\.-]?\d{3}[\s\.-]?\d{4}$#";
  9. return preg_match($reg, $phone);
  10. }
  11.  
  12. $submit=$_POST['Submit'];
  13. if($submit == Submit)
  14. {
  15. $status = "OK";
  16. $email=$_POST['email'];
  17. $message=$_POST['message'];
  18. $subject=$_POST['subject'];
  19. $name=$_POST['name'];
  20. $phone=$_POST['phone'];
  21. $title=$_POST['title'];
  22. $otros2=$_POST['otros2'];
  23.  
  24. $msg="";
  25. $msgerror="";
  26. //error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
  27.  
  28.  
  29.  
  30. if ( strlen($name) < 1 )
  31. {
  32. $msgerror .="* Nombre invalido.<BR />";
  33. $status= "NOTOK";
  34. }
  35.  
  36.  
  37. //if (!stristr($email,"@") OR !stristr($email,"."))
  38. if(!valida_email($email))
  39. {
  40. $msgerror .="* Mail incorrecto.<BR />";
  41. $status= "NOTOK";
  42. }
  43.  
  44. //if ( strlen($phone) < 9 )
  45. if(validarTelefono($phone))
  46. {
  47. $msgerror .="*Telefono compuesto por 9cifras.<BR />";
  48. $status= "NOTOK";
  49. }
  50.  
  51.  
  52. if($title=="Opcion2")
  53. {
  54. $headers4="[email protected]";
  55. }else if($title=="Opcion1"){
  56. $headers4="[email protected]";
  57. }else if($title=="error"){
  58. $status="NOTOK";
  59. $msgerror .="* Seleccione un titulo.<BR />";
  60. }
  61.  
  62.  
  63. if ( strlen($message) < 10 )
  64. {
  65. $msgerror .="* Mensaje minimo 10 caracteres.<BR/>";
  66. $status= "NOTOK";
  67. }
  68.  
  69.  
  70. $body1="<html>
  71. <head>
  72. <p><font face=Tahoma, Helvetica, sans-serif size=2 color=#333333>
  73. <strong>Formulari de Contacte Web:</strong></font><br>
  74. <br><hr width=450px align=left><br>
  75. <font face=Tahoma, Helvetica, sans-serif size=2>
  76.  
  77. <title>Formulario de Contacto Web</title>
  78. </head>
  79. <body>
  80. <strong>Nombre:</strong> $name.<br>
  81. <strong>Tel&eacute;fono:</strong> $phone.<br>
  82. <strong>T&iacute;tulo:</strong> $title: $otros2.<br>
  83. <strong>Email:</strong> $email.<br>
  84. <strong>Mensaje:</strong> $message.</font></p>
  85. </body>
  86. </html> ";
  87.  
  88. require_once 'phpmailer/class.phpmailer.php';
  89.  
  90. $mail = new PHPMailer ();
  91. $mail -> SetFrom ("[email protected]","[email protected]");
  92. $mail -> AddAddress ("$email","$name");
  93. $mail -> Subject = "$title: $otros2";
  94. $mail -> IsHTML (true);
  95. $mail -> IsSMTP();
  96. $mail -> Host = 'mail.dominio.com';
  97. $mail -> Port = 2626;
  98. $mail -> SMTPDebug = 2;
  99. $mail -> SMTPAuth = true;
  100. $mail -> Username = '[email protected]';
  101. $mail -> Password = 'password';
  102. $mail -> MsgHTML(file_get_contents('www.dominio.com/archivos/recibido.html'));
  103. if ($mail -> Send())
  104. {
  105. $msg=" Enviado.";
  106. }else{
  107. $msgerror=" Error inesperado.";
  108. }
  109.  
  110. $mail = new PHPMailer ();
  111. $mail -> SetFrom ("[email protected]","[email protected]");
  112. $mail -> AddAddress("$headers4");
  113. $mail -> Subject = "$title: $otros2";
  114. $mail -> IsHTML (true); // pones (true) en caso de usar formato HTML
  115. $mail -> IsSMTP();
  116. $mail -> Host = 'mail.dominio.com';
  117. $mail -> Port = 2626;
  118. $mail -> SMTPAuth = true;
  119. $mail -> Username = '[email protected]';
  120. $mail -> Password = 'password';
  121. $mail -> MsgHTML($body1);
  122. $mail -> Send();
  123. }