Inquiry about Phpmailer and link to Gmail account

0

I am wanting to associate a gmail account with Php mailer but I am not having an answer when it comes to receiving data from a form. The page I'm doing is the following and the file I'm doing is the one I attached below. What I do not know if there is something to take into account to generate PHP with gmail.

<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Argentina/Buenos_Aires');

if ((isset($_POST['ecommerce']) && $_POST['ecommerce'] != "") &&
	(isset($_POST['nombre']) && $_POST['nombre'] != "") &&
	(isset($_POST['telefono']) && $_POST['telefono']!= "" ) &&
	(isset($_POST['email']) && $_POST['email']!= "") &&
	(isset($_POST['envio']) && $_POST['envio'] === 'envio')  ){

 
	require_once('mailer/class.phpmailer.php');


	
	$emailCliente = "[email protected]";
	$passwordCliente = "xxx17";

   	
	$fromCliente = $emailCliente;


	$ecommerce = $_POST["ecommerce"];
	$nombre = $_POST["nombre"];
	$telefono = $_POST["telefono"];
	$email = $_POST["email"];
	$envio =  $_POST['envio'];
	$address = $email;

	$body  = 
	"
	Datos enviados por el usuario desde el Formulario de contacto: <br/> 
	
	<strong>Ecommerce:</strong> $ecommerce <br/>
	<strong>Nombre y Apellido:</strong> $nombre <br/>
	<strong>Teléfono:</strong> $telefono <br/>
	<strong>Email:</strong> $email <br/>

	"; 
	
	$mail = new PHPMailer();
	$mail->IsSMTP();
	$mail->CharSet = 'UTF-8';
	$mail->Host = "smtp.gmail.com"; // saber que tipo de cuenta.
	$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
	$mail->SMTPAuth= true;
	$mail->Port = 465;
	$mail->Username= $emailCliente; // su cuenta de correo
	$mail->Password= $passwordCliente; // su contraseña 
	$mail->From = $emailCliente; // su cuenta
	$mail->FromName= "Welivery";
	$mail->isHTML(true);
	$mail->Subject ="Mensaje de Welivery";
	$mail->Body = $body;

	$mail->addAddress($address, $nombre);

	if (!$mail->send()) {
	    $output = json_encode(array('type' => 'error', 'text' => 'Error - Comuniquese con el Administrador de la pagina '));
	    die($output);
	} else {
	    $output = json_encode(array('type' => 'message', 'text' => 'Tu mensaje se ha enviado correctamente. A la brevedad nos contactaremos. Muchas gracias'));
	    die($output);
	}

} else {
    $output = json_encode(array('type' => 'message', 'text' =>'No se pudo enviar el email, asegurese que el email exista!!!'));
    die($output);
}
    
asked by Mariano Andres Franco 25.11.2018 в 21:07
source

2 answers

0

This should be a comment but I do not have enough reputation.

What version of PHPMailer are you using?

Do a print_r or var_dump on $ mail-> send () to see the error.

To me with this configuration it worked well (with gmail). I insist that I do not know what version of PHPMailer you are using, but in any case, if you do not have the latest version, it would be advisable to use it.

        require('PHPMailer_v5.1/class.phpmailer.php');
        $mail = new phpmailer(true);

        try{
            $mail->Mailer = 'smtp';
            $mail->Host = 'ssl://smtp.gmail.com';
            $mail->Port = '465';
            $mail->SMTPSecure = 'ssl';
            $mail->SMTPAuth = true;
            $mail->CharSet = 'UTF-8';
            $mail->Username = '...';
            $mail->Password = '...';
            $mail->From = '...';
            $mail->FromName = '...';
            $mail->Timeout = 20;
            $mail->AddAddress("...");
            $mail->Subject = '...';
        }
        catch (phpmailerException $e){
            $err = $e->errorMessage();
            die(print_r($error));
           //si suelta un error, recogelo en un log de errores o mira en el  log de errores de apache o php, aunque con ese die ya lo veras.
        }

Regarding the issue of user and pass, although the ideal would be for the client to use his, unless the volume of emails is very high, I do not think it matters too much that you put another one. After all, it's just a gmail account. Create one (other than yours) and that's it.

    
answered by 26.11.2018 в 00:32
0

<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Argentina/Buenos_Aires');

if ((isset($_POST['ecommerce']) && $_POST['ecommerce'] != "") &&
	(isset($_POST['nombre']) && $_POST['nombre'] != "") &&
	(isset($_POST['telefono']) && $_POST['telefono']!= "" ) &&
	(isset($_POST['email']) && $_POST['email']!= "") &&
	(isset($_POST['envio']) && $_POST['envio'] === 'envio')  ){

 
	require_once('mailer/class.phpmailer.php');


	//MAtest2018.01@gmail   MAtest201801!
	$emailCliente = "[email protected]";
	$passwordCliente = "xxxx";

//	$emailCliente = "[email protected]"; // su cuenta de correo
//	$passwordCliente =  "xxx"; // su contraseña 
	
	$fromCliente = $emailCliente;


	$ecommerce = $_POST["ecommerce"];
	$nombre = $_POST["nombre"];
	$telefono = $_POST["telefono"];
	$email = $_POST["email"];
	$envio =  $_POST['envio'];
	$address = $email;

	$body  = 
	"
	Datos enviados por el usuario desde el Formulario de contacto: <br/> 
	
	<strong>Ecommerce:</strong> $ecommerce <br/>
	<strong>Nombre y Apellido:</strong> $nombre <br/>
	<strong>Teléfono:</strong> $telefono <br/>
	<strong>Email:</strong> $email <br/>

	"; 
	
	$mail = new PHPMailer();
	$mail->IsSMTP();
	$mail->CharSet = 'UTF-8';
	$mail->Host = "smtp.gmail.com"; // saber que tipo de cuenta.
	$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
	$mail->SMTPAuth= true;
	$mail->Port = 587;
	$mail->Username= $emailCliente; // su cuenta de correo
	$mail->Password= $passwordCliente; // su contraseña 
	$mail->From = $emailCliente; // su cuenta
	$mail->FromName= "Welivery";
	$mail->isHTML(true);
	$mail->Subject ="Mensaje de Welivery";
	$mail->Body = $body;

	$mail->addAddress("[email protected]", $nombre);

	if (!$mail->send()) {
	    $output = json_encode(array('type' => 'error', 'text' => 'Error - Comuniquese con el Administrador de la pagina '));
	    die($output);
	} else {
	    $output = json_encode(array('type' => 'message', 'text' => 'Tu mensaje se ha enviado correctamente. A la brevedad nos contactaremos. Muchas gracias'));
	    die($output);
	}

	/*
	$ecommerce = $_POST["ecommerce"];
	$nombre = $_POST["nombre"];
	$telefono = $_POST["telefono"];
	$email = $_POST["email"];
	$envio = $_POST['envio'];


	$body  = 
	"
	En brevedad nos estaremos comunicando.

	Muchas Gracias!

	"; 
	
	$mail = new PHPMailer();
	$mail->IsSMTP();
	$mail->CharSet = 'UTF-8';
	$mail->Host = "smtp.gmail.com"; // saber que tipo de cuenta.
	$mail->SMTPAuth= true;
	$mail->Port = 587;
	$mail->Username= "[email protected]"; // su cuenta de correo
	$mail->Password= "marianoandres"; // su contraseña 
	$mail->SMTPSecure = 'tls';
	$mail->From = "[email protected]"; // su cuenta
	$mail->FromName= "Welivery";
	$mail->isHTML(true);
	$mail->Subject ="Mensaje de Welivery";
	$mail->Body =$body;

	// $address = $email; // 
	$mail->addAddress($email);

	if (!$mail->send()) {
	    $output = json_encode(array('type' => 'error', 'text' => 'Error - Comuniquese con el Administrador de la pagina '));
	    die($output);
	} else {
	    $output = json_encode(array('type' => 'message', 'text' => 'Tu mensaje se ha enviado correctamente. A la brevedad nos contactaremos. Muchas gracias'));
	    die($output);
	}*/



} else {
    $output = json_encode(array('type' => 'message', 'text' =>'No se pudo enviar el email, asegurese que el email exista!!!'));
    die($output);
}
    
answered by 29.11.2018 в 16:27