El formulario siguiente, "code_generator.phps", fue simplificado del PHPMailer v5.2.16.
Puedo enviar a todo los correos con dominios de hosting, tambien envia modo SMTP.
ejemplo: [email protected], [email protected], [email protected], etc..
PROBLEMA:
No puedo enviar a los correos de Gmail. (Nose si envia Yahoo, hotmail, etc no he probado aun)
Ejemplo 1: Si soy un cliente y mi correo es Gmail,
el formulario envia, pero no llega nunca al correo de la web.
Ejemplo 2: Si soy un cliente y tengo el correo de mi web,
"[email protected]" y con ese email si llegan al correo de la web.
Donde dice: ""Email"" ""<?php echo $from_email; ?>"""
es donde va el correo correo del cliente
Donde dice: ""Email del contacto web" ""<?php echo $to_email; ?>"""
es donde va el correo del propietario de la web
Espero me puedan ayudar a solucionar, Muchas Gracias.
Código PHP:
   
<?php
require 'PHPMailerAutoload.php';
 
$CFG['smtp_debug'] = 2; //0 == apagado, 1 para la salida de cliente, 2 para el cliente y el servidor
$CFG['smtp_debugoutput'] = 'html';
$CFG['smtp_server'] = 'localhost';
$CFG['smtp_port'] = '25'; //  25, 465 o 587
$CFG['smtp_authenticate'] = false;
$CFG['smtp_username'] = '[email protected]';
$CFG['smtp_password'] = 'yourpassword';
$CFG['smtp_secure'] = 'None'; // tls, ssl
 
$from_name = (isset($_POST['From_Name'])) ? $_POST['From_Name'] : '';
$from_email = (isset($_POST['From_Email'])) ? $_POST['From_Email'] : '';
$to_name = (isset($_POST['To_Name'])) ? $_POST['To_Name'] : '';
$to_email = (isset($_POST['To_Email'])) ? $_POST['To_Email'] : '';
$cc_email = (isset($_POST['cc_Email'])) ? $_POST['cc_Email'] : '';
$bcc_email = (isset($_POST['bcc_Email'])) ? $_POST['bcc_Email'] : '';
$subject = (isset($_POST['Subject'])) ? $_POST['Subject'] : '';
$message = (isset($_POST['Message'])) ? $_POST['Message'] : '';
$test_type = (isset($_POST['test_type'])) ? $_POST['test_type'] : 'smtp'; // mail, sendmail, smtp
 
$smtp_debug = (isset($_POST['smtp_debug'])) ? $_POST['smtp_debug'] : $CFG['smtp_debug'];
$smtp_server = (isset($_POST['smtp_server'])) ? $_POST['smtp_server'] : $CFG['smtp_server'];
$smtp_port = (isset($_POST['smtp_port'])) ? $_POST['smtp_port'] : $CFG['smtp_port'];
$smtp_secure = strtolower((isset($_POST['smtp_secure'])) ? $_POST['smtp_secure'] : $CFG['smtp_secure']);
 
$smtp_authenticate = (isset($_POST['smtp_authenticate'])) ?
                $_POST['smtp_authenticate'] : $CFG['smtp_authenticate'];
$authenticate_password = (isset($_POST['authenticate_password'])) ?
                $_POST['authenticate_password'] : $CFG['smtp_password'];
$authenticate_username = (isset($_POST['authenticate_username'])) ?
                $_POST['authenticate_username'] : $CFG['smtp_username'];
 
$results_messages = array();
 
$mail = new PHPMailer(true); 
$mail->CharSet = 'utf-8';
ini_set('default_charset', 'UTF-8');
$mail->Debugoutput = $CFG['smtp_debugoutput'];
 
class phpmailerAppException extends phpmailerException    {
}
try {
    if (isset($_POST["submit"]) && $_POST['submit'] == "Enviar") {
        $to = $_POST['To_Email'];
        if (!PHPMailer::validateAddress($to)) {
            throw new phpmailerAppException("Correo electrónico " . $to . " no es válido - abortar!");
        }
 
        try {
            if ($_POST['From_Name'] != '') {
                $mail->addReplyTo($_POST['From_Email'], $_POST['From_Name']);
                $mail->setFrom($_POST['From_Email'], $_POST['From_Name']);
 
            } else {
                $mail->addReplyTo($_POST['From_Email']);
                $mail->setFrom($_POST['From_Email'], $_POST['From_Email']);
 
            }
            if ($_POST['To_Name'] != '') {
                $mail->addAddress($to, $_POST['To_Name']);
            } else {
                $mail->addAddress($to);
            }
            if ($_POST['bcc_Email'] != '') {
                $indiBCC = explode(" ", $_POST['bcc_Email']);
                foreach ($indiBCC as $key => $value) {
                    $mail->addBCC($value);
                }
            }
            if ($_POST['cc_Email'] != '') {
                $indiCC = explode(" ", $_POST['cc_Email']);
                foreach ($indiCC as $key => $value) {
                    $mail->addCC($value);
                }
            }
        } catch (phpmailerException $e) { //
            throw new phpmailerAppException($e->getMessage());
        }
        $mail->Subject = $_POST['Subject'] . ' (Website ' . strtoupper($_POST['test_type']) . ')';
 
        if ($_POST['Message'] == '') {
            $body = file_get_contents('contents.html'); //Mensaje esta vacio envia un html
        } else {
            $body = $_POST['Message'];
        }
 
        $mail->WordWrap = 78; // Limite del texto RFC2822 
        $mail->msgHTML($body, dirname(__FILE__), true); //Crear cuerpos de mensaje y incluir imágenes
 
        try {
            $mail->send();
            $results_messages[] = "mensaje enviado " . strtoupper($_POST["test_type"]);
        } catch (phpmailerException $e) {
            throw new phpmailerAppException("No se puede enviar a: " . $to . ': ' . $e->getMessage());
        }
    }
} catch (phpmailerAppException $e) {
    $results_messages[] = $e->errorMessage();
}
 
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>PHPMailer </title>
</head>
<body>
<?php
if (count($results_messages) > 0) {
    echo '<h2>resultados de la ejecución</h2>';
    echo '<ul>';
    foreach ($results_messages as $result) {
        echo "<li>$result</li>";
    }
    echo '</ul>';
}
 
 
 
 
?>
<form method="POST" enctype="multipart/form-data">
 
                <table border="1" class="column">
                    <tr>
                        <td>
                        Nombre y Apellidos:        
                        </td>
                        <td>
                            <input type="text" id="From_Name" name="From_Name" value="<?php echo $from_name; ?>"
                                   style="width:95%;" autofocus placeholder="Nombres">
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Email
                        </td>
                        <td>
                            <input type="text" id="From_Email" name="From_Email" value="<?php echo $from_email; ?>"
                                   style="width:95%;" required placeholder="Tu Email">
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Nombre del contacto web
                        </td>
                        <td>
                            <input type="text" id="To_Name" name="To_Name" value="<?php echo $to_name; ?>"
                                   style="width:95%;" placeholder="NombresOwner">
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Email del contacto web
                        </td>
                        <td class="colrite">
                            <input type="text" id="To_Email" name="To_Email" value="<?php echo $to_email; ?>"
                                   style="width:95%;" required placeholder="[email protected]">
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Con Copia (CC) (separada por comas)
                        </td>
                        <td>
                            <input type="text" id="cc_Email" name="cc_Email" value="<?php echo $cc_email; ?>"
                                   style="width:95%;" placeholder="[email protected], [email protected]">
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Email Copia Oculta (BCC) (separada por comas)
                        </td>
                        <td>
                            <input type="text" id="bcc_Email" name="bcc_Email" value="<?php echo $bcc_email; ?>"
                                   style="width:95%;" placeholder="[email protected], [email protected]">
                        </td>
                    </tr>
                    <tr>
                        <td>
                      Asunto
                        </td>
                        <td>
                            <input type="text" name="Subject" id="Subject" value="<?php echo $subject; ?>"
                                   style="width:95%;" placeholder="Asunto">
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Detalles  <small>Si está en blanco, se utilizará content.html</small>
                        </td>
                        <td>
                            <textarea name="Message" id="Message" style="width:95%;height:5em;"
                                      placeholder="Su mensaje."><?php echo $message; ?></textarea>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </div>
                <input type="submit" value="Enviar" name="submit" id="submit">
    </div>
</form>
</body>
</html>   
 

