Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/03/2015, 08:43
conik500
 
Fecha de Ingreso: noviembre-2014
Ubicación: Granada
Mensajes: 7
Antigüedad: 9 años, 5 meses
Puntos: 1
Pregunta Respuesta: Dos clicks en el mismo botón

Esto es la función a la que se llama al pulsar el botón

Código:
function enviarcorreo(){

  asunto=document.form.asunto.value;
  muni=document.form.municipio.value;
  cuerpo='<b>Municipio:</b>' + muni + '<br>' + document.form.cuerpo.value;

  correo=document.form.correo.value;
  
  
  if (cuerpo=='' || asunto==''){
	 alert('Debe rellenar todos los campos');
	 
  }else{
	 
////////////////////////////////////////////////////////////////////////////////////////////////Saber correo
	  ajax21=objetoAjax();

	
	ajax21.open("POST", "emailemail.php",true);
	
	ajax21.onreadystatechange=function(){
		 
		if (ajax21.readyState==4) {
			
			 correo12 = ajax21.responseText;
			

		}
	}
		ajax21.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	

		
		ajax21.send("nombre="+correo);
		
		
////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////Saber filtro
		  ajax3=objetoAjax();

		ajax3.open("POST", "filtroemail.php",true);
		
		ajax3.onreadystatechange=function() {
			 
			if (ajax3.readyState==4) {
				
				filtro12 = ajax3.responseText;
				
			}
		}
			ajax3.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			
			
			ajax3.send("nombre="+correo);
			
			
	////////////////////////////////////////////////////////////////////////////////////////	
			document.getElementById('alenviando').style.display="block";
				
ajax6=objetoAjax();

ajax6.open("POST", "mail2.php",true);

ajax6.onreadystatechange=function(){
	
	if (ajax6.readyState==4) {
		
		
		var valor = ajax6.responseText;

		
		       if (valor==1){
		    	   
		    	   window.location ="indexidentificado.php?datado=2";
		       }else{
		    	   alert('No se ha enviado');
		       }
		
		

	}
}
	ajax6.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	
	ajax6.send("asunto="+filtro12+" - "+asunto+"&cuerpo="+cuerpo+"&correo="+correo12);
	
	
	
  
  }
}
Esta trae los datos correo y filtro del asunto y después llama al php,

Código PHP:

require ('PHPMailer/class.phpmailer.php');
require (
"PHPMailer/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail             = new PHPMailer();
$body             $_POST["cuerpo"];

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       "MI SERVIDOR"// SMTP server

$mail->From "CORREO DESDE EL QUE SE MANDA";

// nombre remitente, p. ej.: "Servicio de envío automático"
$mail->FromName "NOMBRE";
// enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only// asunto y cuerpo alternativo del mensaje
$mail->Subject $_POST["asunto"];
$mail->AltBody "Cuerpo alternativo 
    para cuando el visor no puede leer HTML en el cuerpo"


// si el cuerpo del mensaje es HTML
$mail->MsgHTML($body);

// podemos hacer varios AddAdress
$mail->AddAddress($_POST["correo"], "NOMBRE");

// si el SMTP necesita autenticación
$mail->SMTPAuth true;

// credenciales usuario
$mail->Username "USUARIO";
$mail->Password "CONTRASEÑA"
$mail->CharSet'UTF-8';
if(!
$mail->Send()) {
echo 
"0";
} else {
echo 
"1";

Gracias