[SOLUCIONADO] Integracion de GoogleMaps con AJAX, enviar mapa por email

Iniciado por graphixx, Septiembre 12, 2014, 01:31:11 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Septiembre 12, 2014, 01:31:11 PM Ultima modificación: Septiembre 13, 2014, 03:06:15 PM por blackdrake
Primero que todo estoy usando PHPMailer por lo que mas adelante pienso consumir miles de correos al dia y usar SMTP por eso no use simplemente mail. Y pues estoy tratando de hacer un POST Dinamico con AJAX a al script donde envio el email y no me da.

Index.html
Código: php

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="robots" content="noindex,follow"/>
<title>Geolocalizacion con HTML5</title>
<link rel="shortcut icon" href="/favicon.ico" />
<style type="text/css">img{border:0}</style>
</head>
<body onload="detectar()">
<div id="mapa">
</div>
<!--email -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!--email -->
<script src="http://code.google.com/apis/gears/gears_init.js" type="text/javascript" charset="utf-8"></script>
<script src="geo.js" type="text/javascript" charset="utf-8"></script>
<script language="javascript">
function detectar(){
if(geo_position_js.init())
{
document.getElementById('mapa').innerHTML="Leyendo...";
geo_position_js.getCurrentPosition(mostra_ubicacion,function(){document.getElementById('mapa').innerHTML="No se pudo detectar la ubicación"},{enableHighAccuracy:true});
} else {
document.getElementById('mapa').innerHTML="La geolocalización no funciona en este navegador.";
}
}
function mostra_ubicacion(p){
var coords = p.coords.latitude + "," + p.coords.longitude;

//email
var url= "email_geo_simple.php";
$.ajax({
type: "post",
url:url,
data:{coord:coords},
beforeSend: function()
{
$('#mensaje').html("Cargando...");
},
success: function(datos)
{
   $('#mensaje').html(datos);    
}
});
//email

document.getElementById('mapa').innerHTML="<a href=\"http://maps.google.com/?q="+coords+"\"><img src=\"http://maps.google.com/maps/api/staticmap?center="+coords+"&maptype=roadmap&size=400x400&zoom=15&markers=size:mid|"+coords+"&sensor=false\" alt=\"mapa\"/></a>";
}


</script>
</body>
</html>


email_geo_simple.php
Código: php

<?php
require_once 'email/class.phpmailer.php';

$coord = $_POST["coord"];

$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

$email = '<a href=\"http://maps.google.com/?q='.$coord.'"\"><img src=\"http://maps.google.com/maps/api/staticmap?center='.$coord.'&maptype=roadmap&size=400x400&zoom=15&markers=size:mid|'.$coord.'&sensor=false\" alt=\"mapa\"/></a>';

try {
  $mail->AddReplyTo('[email protected]', 'Medica');
  $mail->AddAddress('[email protected]', 'Medica');
  $mail->SetFrom('[email protected]', 'Medica');
  $mail->AddReplyTo('[email protected]', 'Medica');
  $mail->Subject = 'Su perfil medico ha sido consultado';
  $mail->AltBody = 'Para ver este mensaje, por favor use un cliente de correo compatible con HTML!'; // optional - MsgHTML will create an alternate automatically
  //$mail->MsgHTML(file_get_contents('contents.html'));
  $mail->MsgHTML($email);
  //$mail->AddAttachment('images/phpmailer.gif');      // attachment
  //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  $mail->Send();
  echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
   
?>


Si alguien me sabe indicar por que no se ejecuta : email_geo_simple.php, se agradece.

Script completo:
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta




Listo ya llega el mapa de google maps con geolocalizacion al email, dejo el codigo final:
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

Gracias a todos los que colaboraron!!!
Mi Blog Personal
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

Perfecto, me alegro de que te funcione, cierro tema y marco como solucionado.

PD: Lee el mp que te envié.