Click to See Complete Forum and Search --> : Sending PHP variables in mail()


r4gn0
07-09-2008, 10:18 AM
Hi, im trying to send php variables in a mail that has an html table, the mail arrives but without body!!! can someone tell me whats wrong with this??


<?php
require_once('../Connections/principal.php');
$miconexion = new Db("redes","localhost","userred","passred");
$idcliente=$_GET['cliente'];
$fecha = date("d-M-y");
$fechan = $fecha;
$texto=$_GET['texto'];
$prioridad=$_GET['prioridad'];
$temp=$miconexion->consulta("SELECT cliente FROM usuario WHERE id='$idcliente'");
while ($row=mysql_fetch_row($temp))
{
$nombre=$row['0'];
}
$norden=$miconexion->consulta("SELECT num_orden FROM orden");
while ($row=mysql_fetch_row($norden))
{
$nun_orden=$row['0'] + 1;
}
$miconexion->consulta("INSERT INTO orden VALUES ('".$idcliente."','".$nombre."','".$nun_orden."','".$texto."','".$prioridad."','".$fecha."','".$fechan."')");
$contenido='
<html>
<head>
<title>Confirmaci&oacute;n de Registro de Usuario/title>
</head>
<body>
<table width="600" border="1">
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">El usuario <b>'.$nombre.'</b> ha reportado el siguiente problema:</font></td>
</tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="/* 003366">'.$texto.'</font></td>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">la prioridad para este es: <b>'.$prioridad.'</b></font></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">El problema fue reportado el d&iacute;a:'.$fecha.'</font></td>
</tr>
</table>
<font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="/* FF0000">Por favor no responda este correo ya que nadie lo recibir&aacute;</font>
</body>
</html>';
$cabeceras = 'MIME-Version: 1.0' . "\r\n";
$cabeceras .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$cabeceras .= 'From: Mecatronics Ltda < noreply@mecatronicsltda.com >' . "\r\n";
mail ("Ingenieros de Soporte < mail@mail.com >", "Solicitud Servicio",$contenido,$cabeceras);
header ("location: ../clientes/clientes.php");

alexus
07-09-2008, 10:45 AM
a) try to disable this line:
$cabeceras = 'MIME-Version: 1.0' . "\r\n";

in my case that helped form me.

Also try to output the variables before you sending the mail to make sure your variables actually have any values in them.

mitya
07-09-2008, 10:57 AM
Yes, most problems like this are down to missing headers, as Alexus suggested.

r4gn0
07-09-2008, 11:04 AM
I disabled the line:

$cabeceras = 'MIME-Version: 1.0' . "\r\n";

and checked if the variables have values...indeed they had, but i still recieve the mail without body!

here is the link (http://servicios.mecatronicsltda.com/reportes/orden.php) of the page, when you click in "crear" it goes to insertorden.php that has the code above, it also print the values of the variables


echo $nombre;
echo $texto;
echo $prioridad;
echo $fecha;

r4gn0
07-09-2008, 11:07 AM
Other thing, when i send the mail without php variables it doesnt works!

alexus
07-09-2008, 11:14 AM
ok so in another word your mail function doesnt work
so how about just create plane new page with only the mail function on it and then try to send plain text (NO Htmal) is that works add HTML, then add variables

r4gn0
07-09-2008, 11:23 AM
the mail function works, i replace the "body" of the mail with


<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>


and it works...

r4gn0
07-09-2008, 11:28 AM
I found the problem! i deleted the line


<font face="Verdana, Arial, Helvetica, sans-serif" size="2">.......</font>


and it worked!
so...how can i use font types i the mail?

r4gn0
07-09-2008, 11:32 AM
Don't Worry, i found the solution!


<font face="/* Verdana, Arial, Helvetica, sans-serif" size="/* 10">

alexus
07-09-2008, 11:38 AM
oh i didnt see that thingie... tats not the problem with the font it problem with /*
that symbol in PHP means we are quoting out the code...
so
//quoted out text will not be shown
echo "in similar way"; /* this part will not be shown as it is quoted out, notice begining and the end of the quotes */


in tour case you opened PHP quote and dint close it as result you quored out the rest of your code.

So try this:


<font face="Verdana, Arial, Helvetica, sans-serif" size="10">