Click to See Complete Forum and Search --> : Php mail arrives twice
djinn4f
10-24-2006, 06:57 PM
Hi!
I have a problem with php's mail function and I'm so desperate!!
I need to send a mail to an address received by means of a form.
The form code is normal html, using GET method.
I get form data, put them in a data base and send a mail to that user's data address:
<?php
$mailVectoraula .= "Hello";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: boletin@vectoraula.com";
$asunto = "Suscripción";
//connecting to data base
$link = mysql_connect("localhost","root","");
$db_selected = mysql_select_db("vectoraula",$link);
//get user's data
$Name = $_GET['name'];
$Mail = $_GET['mail'];
$Lastname = $_GET['lastname'];
//insert into data base
mysql_query("insert into datos_formularios (first,second, mail) values ('$Name','$Lastname','$Mail')", mysql_connect("localhost","",""));
//send mail to user
mail($Mail,$asunto,$mailVectoraula,$headers); //enviamos el mail
//close connection
mysql_close(mysql_connect("localhost","","")); //cierra la conexion
?>
The thing is it sends the same mail twice and I'm tired of looking and thinking without finding out anything.
The data base works fine.
I hope someone would help me.
Thank you so much!!!!!
NogDog
10-24-2006, 07:22 PM
I don't see anything obvious that would cause that. Do you by any chance do something elsewhere in the code that would cause the page to reload for some reason?
djinn4f
10-24-2006, 08:07 PM
Thank you so much for answering me!!
I already thought about it but didn't see anything. Before I posted a resumed translated code because mine is in Spanish but here's everything I have. Maybe there's something I didn't realize and you're able to see it:
<!-- Documento que procesa los datos de un usuario que utiliza la web www.vectoraula.com. Se incluyen los datos en la base de datos "vectoraula" tabla "datos_formulario". Además se envía al usuario un mail de respuesta cuando se apunta.-->
<html>
<head>
<title>Envio de usuario a base de datos y mail respuesta</title>
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=http://www.vectoraula.com/">
</head>
<body>
<?php
//variable que contendra el cuerpo de cada mail de respuesta
$mailVectoraula = "<html>";
$mailVectoraula .= "<head>";
$mailVectoraula .= "<title>Mail VectorAula</title>";
$mailVectoraula .= "</head>";
$mailVectoraula .= "<body>";
$mailVectoraula .= "Se ha suscrito al boletin de vectoraula.<br>";
$mailVectoraula .= "<br>";
$mailVectoraula .= "Un saludo.<br>";
$mailVectoraula .= "</body>";
$mailVectoraula .= "</html>";
//cabeceras necesarias para enviar formato HTML
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: boletin@vectoraula.com";//direccion que figura como from en el mail
$asunto = "Suscripción";
function Conectarse()
{
$link = mysql_connect("localhost","","");
if (!$link) // me conecto a la bbdd
{
echo "<br>Error conectando a la base de datos.";
exit();
}
$db_selected = mysql_select_db("vectoraula",$link);
if (!$db_selected) // selección de la base de datos
{
echo "<br>Error seleccionando la base de datos.";
exit();
}
} //fin de la funcion para conectarse a la bbdd
// llamamos a la funcion que nos conecta a la base de datos
Conectarse();
//creo variables con los datos del formulario
$Nombre = $_GET['nombre'];
$Mail = $_GET['mail'];
$Apellidos = $_GET['apellidos'];
mysql_query("insert into datos_formularios (nombre,apellidos, mail) values ('$Nombre','$Apellidos','$Mail')", mysql_connect("localhost","","")); //hago la peticion
mail($Mail,$asunto,$mailVectoraula,$headers); //enviamos el mail
mysql_close(mysql_connect("localhost","","")); //cierra la conexion
?>
<br>
</body>
</html>
Just in case you think could be worthy, here's also my form code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
alert(msg);
}
//-->
</script>
</head>
<script language="JavaScript" type="text/JavaScript"></script>
<body>
<form action="procesarDatosVectoraula.php" method="get" name="datos" id="datos">
<input name="nombre" type="text" id="nombre">
<input name="apellidos" type="text" id="apellidos">
<input name="mail" type="text" id="mail">
<input name="Enviar" type="submit" id="Enviar" onClick="MM_popupMsg('Gracias por inscribirse en el boletín. Próximamente comenzará a recibirlo')" value="Enviar">
</form>
</body>
</html>
If there's something wrong in the code I really don't get it. Thanks for give it a thought.
Could be something with the server? But I don't know what could be!!!
Thank you so much.
aussie girl
10-24-2006, 09:43 PM
perhaps it's this part
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=http://www.vectoraula.com/">
that reloads the page, I don't see why you would need to keep refreshing this page
djinn4f
10-25-2006, 05:15 AM
I have to redirect user to www.vectoraula.com after he introduce data in the form. That's why I put this tag.
I saw it in many places to redirect.
Maybe there's another option for HTTP-EQUIV besides Refresh? I didn't find it.