PHP - Servidor FMPT desde gmail sin hosting

 
Vista:
Imágen de perfil de jonathan

Servidor FMPT desde gmail sin hosting

Publicado por jonathan (7 intervenciones) el 28/09/2015 01:18:24
buenas comunidad intento realizar un envio de mail desde el formulario en php usando el fmpt de Gmail pues no tengo un Hosting aun pero no logro hacerlo

/***Este es el form que envia el Mail

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$de = $_POST["de_txt"];
$para = $_POST["para_txt"];
$asunto = $_POST["asunto_txt"];
$mensaje = $_POST["mensaje_txa"];
$cabeceras = "MIME-Version: 1.0\r\n";
$cabeceras .= "Content-type: text/html; charset=iso-8859-1\r\n";
$cabeceras .= "From: $de \r\n";
 
$archivo = $_FILES["archivo_fls"]["tmp_name"];
$destino = $_FILES["archivo_fls"]["name"];
 
if(move_uploaded_file($archivo,$destino)){
	//incluyo la clase phpmailer		
	include_once("class.phpmailer.php");
	include_once("class.smtp.php");
 
	$mail = new PHPMailer(); //creo un objeto de tipo PHPMailer
	$mail->IsSMTP(); //protocolo SMTP
	$mail->SMTPAuth = true;//autenticación en el SMTP
	$mail->SMTPSecure = "ssl";//SSL security socket layer
	$mail->Host = "smtp.gmail.com";//servidor de SMTP de gmail
	$mail->Port = 465;//puerto seguro del servidor SMTP de gmail
	$mail->From = $de; //Remitente del correo
	$mail->AddAddress($para);// Destinatario
	$mail->Username = "jonathancalderon.huawei@gmail.com";//Aqui pon tu correo de gmail
	$mail->Password = "";//Aqui pon tu contraseña de gmail
	$mail->Subject = $asunto; //Asunto del correo
	$mail->Body = $mensaje; //Contenido del correo
	$mail->WordWrap = 50; //No. de columnas
	$mail->MsgHTML($mensaje);//Se indica que el cuerpo del correo tendrá formato html
	$mail->AddAttachment($destino); //accedemos al archivo que se subio al servidor y lo adjuntamos
 
	if($mail->Send()){ //enviamos el correo por PHPMailer
		$respuesta = "El mensaje ha sido enviado con la clase PHPMailer y tu cuenta de gmail =)";
	} else{
		$respuesta = "El mensaje no se pudo enviar con la clase PHPMailer y tu cuenta de gmail =(";
	   	$respuesta .= " Error: ".$mail->ErrorInfo;
	}
} else {
	$respuesta = "Ocurrio un error al subir el archivo adjunto =(";
}
 
unlink($destino); //borramos el archivo del servidor
 
header("Location: formulario-phpmailer.php?respuesta=$respuesta");
?>


este form Valida los campos de Texto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="es">
<head>
	<meta charset="utf-8" />
	<title>Env&iacute;o de correo con la funci&oacute;n mail de PHP</title>
	<style>
		form {
			margin: 1em auto;
			text-align: center;
		}
 
		span {
				color: #F60;
				font-size: 1.5em;
		}
	</style>
	<script>
		function validarForm(){
			var verificar = true;
			var expRegEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
 
			if(!document.mail_frm.de_txt.value){
				alert("El campo 'De' es requerido");
				document.mail_frm.de_txt.focus();
				verificar = false;
			} else if(!expRegEmail.exec(document.mail_frm.de_txt.value)){
				alert("El campo 'De' no es v�lido");
				document.mail_frm.de_txt.focus();
				verificar = false;
			} else if(!document.mail_frm.para_txt.value){
				alert("El campo 'Para' es requerido");
				document.mail_frm.para_txt.focus();
				verificar = false;
			} else if(!expRegEmail.exec(document.mail_frm.para_txt.value)){
				alert("El campo 'Para' no es v�lido");
				document.mail_frm.para_txt.focus();
				verificar = false;
			} else if(!document.mail_frm.asunto_txt.value){
				alert("El campo 'Asunto' es requerido");
				document.mail_frm.asunto_txt.focus();
				verificar = false;
			} else if(!document.mail_frm.mensaje_txa.value){
				alert("El campo 'Mensaje' es requerido");
				document.mail_frm.mensaje_txa.focus();
				verificar = false;
			} else if(!document.mail_frm.archivo_fls.value){
				alert("El campo 'Adjuntar archivo' es requerido");
				document.mail_frm.archivo_fls.focus();
				verificar = false;
			}
 
			if(verificar){
				document.mail_frm.submit();
			}
		}
 
		window.onload = function(){
			document.mail_frm.enviar_btn.onclick = validarForm;
		}
	</script>
</head>
<body>
	<form name="mail_frm" action="enviar-phpmailer.php" method="post" enctype="multipart/form-data">
		De: <input type="text" name="de_txt" /><br /><br />
		Para: <input type="text" name="para_txt" /><br /><br />
		Asunto: <input type="text" name="asunto_txt" /><br /><br />
		Adjuntar archivo: <input type="file" name="archivo_fls" /><br /><br />
		Mensaje:<br /><textarea name="mensaje_txa"></textarea><br /><br />
		<input type="button" name="enviar_btn" value="Enviar" /><br />
		<?php
		error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
		if(isset($_GET["respuesta"])){
			echo "<span>".$_GET["respuesta"]."</span>";
		}
		?>
	</form>
</body>
</html>


Este es el error

El mensaje no se pudo enviar con la clase PHPMailer y tu cuenta de gmail =( Error: SMTP Error: Could not authenticate.

corro el Xampp con mysql

gracias de ante mano
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Servidor FMPT desde gmail sin hosting

Publicado por xve (6935 intervenciones) el 28/09/2015 08:52:46
Hola Jonathan, cuando yo utilizo gmail, la seguridad que utilizo es TLS, no SSL...
1
$smtp->SMTPSecure = "tls";

Confírmanos si es este el problema.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de jonathan

Servidor FMPT desde gmail sin hosting

Publicado por jonathan (7 intervenciones) el 29/09/2015 02:14:38
Muchas gracias por tu ayuda hice la modificación en la linea que tu me sugeriste



pero aun persiste el error

El mensaje no se pudo enviar con la clase PHPMailer y tu cuenta de gmail =( Error: SMTP Error: Could not authenticate.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
$de = $_POST["de_txt"];
$para = $_POST["para_txt"];
$asunto = $_POST["asunto_txt"];
$mensaje = $_POST["mensaje_txa"];
$cabeceras = "MIME-Version: 1.0\r\n";
$cabeceras .= "Content-type: text/html; charset=iso-8859-1\r\n";
$cabeceras .= "From: $de \r\n";
 
/*$archivo = $_FILES["archivo_fls"]["tmp_name"];*/
$destino = $_FILES["archivo_fls"]["name"];
 
if(move_uploaded_file($archivo,$destino)){
	//incluyo la clase phpmailer		
	include_once("class.phpmailer.php");
	include_once("class.smtp.php");
 
	$mail = new PHPMailer(); //creo un objeto de tipo PHPMailer
	$mail->IsSMTP(); //protocolo SMTP
	$mail->SMTPAuth = true;//autenticación en el SMTP
	$mail->SMTPSecure = "tls";
	/*$mail->SMTPSecure = "ssl";//SSL security socket layer*/
	$mail->Host = "smtp.gmail.com";//servidor de SMTP de gmail
	$mail->Port = 465;//puerto seguro del servidor SMTP de gmail
	$mail->From = $de; //Remitente del correo
	$mail->AddAddress($para);// Destinatario
	$mail->Username = "mipcjj@gmail.com";//Aqui pon tu correo de gmail
	$mail->Password = "mipcstore2014";//Aqui pon tu contraseña de gmail
	$mail->Subject = $asunto; //Asunto del correo
	$mail->Body = $mensaje; //Contenido del correo
	$mail->WordWrap = 50; //No. de columnas
	$mail->MsgHTML($mensaje);//Se indica que el cuerpo del correo tendrá formato html
	$mail->AddAttachment($destino); //accedemos al archivo que se subio al servidor y lo adjuntamos
 
	if($mail->Send()){ //enviamos el correo por PHPMailer
		$respuesta = "El mensaje ha sido enviado con la clase PHPMailer y tu cuenta de gmail =)";
	} else{
		$respuesta = "El mensaje no se pudo enviar con la clase PHPMailer y tu cuenta de gmail =(";
	   	$respuesta .= " Error: ".$mail->ErrorInfo;
	}
} else {
	$respuesta = "Ocurrio un error al subir el archivo adjunto =(";
}
 
unlink($destino); //borramos el archivo del servidor
 
header("Location: formulario-phpmailer.php?respuesta=$respuesta");
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Servidor FMPT desde gmail sin hosting

Publicado por xve (6935 intervenciones) el 29/09/2015 08:17:52
Hola Jonathan, perdona, el puerto también es otro...
Estos son los datos que yo utilizo:
1
2
3
4
5
6
$smtp->SMTPAuth   = true;
$smtp->SMTPSecure = "tls";
$smtp->Host       = "smtp.gmail.com";
$smtp->Username   = "miCuenta@gmail.com";
$smtp->Password   = "miPassword";
$smtp->Port       = 587;

coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar