Ver Mensaje Individual
  #8 (permalink)  
Antiguo 13/11/2017, 18:59
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 655
Antigüedad: 21 años, 10 meses
Puntos: 6
Respuesta: email a bandeja de entrada

Probe este codigo y sale error al enviar quiza algo falte corregir,

aunque la validadacion no es tam importante para mi. solo ver si solucionar el error y llegue a la bandeja de entrada bien


Código PHP:

<?php
//index.php

$error = '';
$name = '';
$email = '';
$subject = '';
$message = '';

function 
clean_text($string)
{
    
$string = trim($string);
    
$string = stripslashes($string);
    
$string = htmlspecialchars($string);
    return 
$string;
}

if(isset(
$_POST["submit"]))
{
    if(empty(
$_POST["name"]))
    {
        
$error .= '<p><label class="text-danger">Please Enter your Name</label></p>';
    }
    else
    {
        
$name = clean_text($_POST["name"]);
        if(!
preg_match("/^[a-zA-Z ]*$/",$name))
        {
            
$error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
        }
    }
    if(empty(
$_POST["email"]))
    {
        
$error .= '<p><label class="text-danger">Please Enter your Email</label></p>';
    }
    else
    {
        
$email = clean_text($_POST["email"]);
        if(!
filter_var($email, FILTER_VALIDATE_EMAIL))
        {
            
$error .= '<p><label class="text-danger">Invalid email format</label></p>';
        }
    }
    if(empty(
$_POST["subject"]))
    {
        
$error .= '<p><label class="text-danger">Subject is required</label></p>';
    }
    else
    {
        
$subject = clean_text($_POST["subject"]);
    }
    if(empty(
$_POST["message"]))
    {
        
$error .= '<p><label class="text-danger">Message is required</label></p>';
    }
    else
    {
        
$message = clean_text($_POST["message"]);
    }
    if(
$error == '')
    {
        require 
'class/class.phpmailer.php';
        
$mail = new PHPMailer;
        
$mail->IsSMTP();                                //Sets Mailer to send message using SMTP
        
$mail->Host = 'smtp.miweb.com';        //Sets the SMTP hosts of your Email hosting, this for Godaddy
        
$mail->Port = '80';                                //Sets the default SMTP server port
        
$mail->SMTPAuth = true;                            //Sets SMTP authentication. Utilizes the Username and Password variables
        
$mail->Username = '[email protected]';                    //Sets SMTP username
        
$mail->Password = 'miclave';                    //Sets SMTP password
        
$mail->SMTPSecure = '';                            //Sets connection prefix. Options are "", "ssl" or "tls"
        
$mail->From = $_POST["email"];                    //Sets the From email address for the message
        
$mail->FromName = $_POST["name"];                //Sets the From name of the message
        
$mail->AddAddress('[email protected]', 'Name');        //Adds a "To" address
        
$mail->AddCC($_POST["email"], $_POST["name"]);    //Adds a "Cc" address
        
$mail->WordWrap = 50;                            //Sets word wrapping on the body of the message to a given number of characters
        
$mail->IsHTML(true);                            //Sets message type to HTML                
        
$mail->Subject = $_POST["subject"];                //Sets the Subject of the message
        
$mail->Body = $_POST["message"];                //An HTML or plain text message body
        
if($mail->Send())                                //Send an Email. Return true on success or false on error
        
{
            
$error = '<label class="text-success">Thank you for contacting us</label>';
        }
        else
        {
            
$error = '<label class="text-danger">There is an Error</label>';
        }
        
$name = '';
        
$email = '';
        
$subject = '';
        
$message = '';
    }
}

?>