Problem with ecommerce form

Discussion in 'PHP' started by afonseca, Nov 9, 2006.

  1. #1
    Hi!

    We are experince a small problem with an ecommerce form.
    The situation is this:
    The client after making the purchase is requested to fullfill a form with is data. Then the system will sent an email back to us with all the data and the purchase.
    In our rotine test we just receive the Subject and Header. Nothing else. We dont know why.
    See our code below.
    Does anyone can help?

    Thanks
    António

    -----------------------------------------
    
    <?php require_once('Connections/medical.php'); ?>
    <? session_start(); ?>
    <html>
    <head>
    <title>Formulário</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="medical.css" rel="stylesheet" type="text/css">
    <script language="Javascript1.2">
    
    
    var message = "imprimir esta página";
    
    function printpage() {
    window.print();  
    }
    
    //document.write("<form><input type=button "
    //+"value=\""+message+"\" onClick=\"printpage()\"></form>");
    
    //-->
    </script><link href="images/medical.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <!--
    body {
    	margin-left: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    	margin-top: 0px;
    }
    -->
    </style></head>
    
    <body>
    <table width="500" border="0" cellspacing="8" cellpadding="0">
      <tr>
        <td><img src="images/logobv2.gif" width="163" height="47"></td>
      </tr>
      <tr>
        <td height="2" valign="bottom"><hr size='1' color='#006633' noshade>    </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><?php 
     include("db.php");
     
    $data = date("d-m-Y,G:i");
    $to = "geral@bastosviegas.com"; //
    $nr = $_POST['nr']; 
    $name = $_POST['nome']; 
    $endereco = $_POST['end']; 
    $localidade = $_POST['loc']; 
    $cod_postal = $_POST['cod'];
    $pais = $_POST['pais'];
    $telefone = $_POST['tel']; 
    $fax = $_POST['fax'];
    $profissao = $_POST['prof'];
    $actividade = $_POST['act'];
    $email = $_POST['mail'];
    $nrcont = $_POST['nrcont'];
    $sub = "Encomenda";
    $msg = $_POST['msg'];
    $headers="Dados do Cliente";
    
    //$EmailBody = "Nome: $name\nO Email: $email\nTelefone: $telefone\nEmpresa: $empresa\nMenssagem: $msg\n"; 
    
    
    if(empty($name) || empty($endereco) || empty($localidade) || empty($cod_postal) || empty($pais) || empty($telefone) || empty($profissao) || empty($actividade) || empty($email)) { 
          echo "<div align='center'><font color='#006633' size=9 face='Verdana, Arial, Helvetica, sans-serif'><h5>N&atilde;o preencheu todos os campos obrigatorios - tente novamente.</h5></font></div>";
     	  echo " <meta http-equiv=\"refresh\" content=\"3;URL=encomendar.php\"> ";
    	  exit;
    } 
    
    
    elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z&shy;]{2,3})$", 
    $email)) { 
          echo "<div align='center'><font color='#006633' size=9 face='Verdana, Arial, Helvetica, sans-serif'><h5>O Email que foi inserido n&atilde;o tem um formato valido, por favor insira um email valido</h5></font></div>";
    	echo " <meta http-equiv=\"refresh\" content=\"3;URL=encomendar.php\"> ";
    	  exit;
    } else { 
          
          echo "<div align='center'><font color='#006633' size=9 face='Verdana, Arial, Helvetica, sans-serif'><h5>Obrigado ".$name." os seus dados foram enviados com sucesso</h5></font></div>";
    	  print"<input alt=imprimir border=0 name=submit src='images/print.jpg' type=image onClick='printpage()'><br>";
    	  
    $Emailbody=mailbody($nr,$name,$endereco,$localidade,$cod_postal,$pais,$telefone,$fax,$profissao,$actividade,$email,$nrcont,$msg,$data);
    
    		mail($to, $sub, $Emailbody, $headers);
    		
    		$qrydrop = mysql_query("select * from cart where cookieId = '" . GetCartId() . "' order by cod asc");	
    			
    			while($campos = mysql_fetch_array($qrydrop))
    			{
    			@mysql_query("delete from cart where cookieId = '" . GetCartId() . "' ");
    			
    			}
    	 // exit;
    } 
    
    
    function mailbody($nr,$name,$endereco,$localidade,$cod_postal,$pais,$telefone,$fax,$profissao,$actividade,$email,$nrcont,$msg,$data){
    
    		global $dbServer, $dbUser, $dbPass, $dbName;
    
    		
    		$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);	
    print"<font class='text1'>$data</font><br>";		
    print "<font class='text1'>N&uacute;mero:</font> <font class='texto'>$nr</font><br>";
    print "<font class='text1'>Nome:</font> <font class='texto'>$name</font><br>";
    print "<font class='text1'>Endere&ccedil;o:</font> <font class='texto'>$endereco</font><br>";
    print "<font class='text1'>Localidade:</font> <font class='texto'>$localidade</font><br>";
    print "<font class='text1'>c&oacute;digo postal:</font> <font class='texto'>$cod_postal</font><br>";
    print "<font class='text1'>Pa&iacute;s:</font> <font class='texto'>$pais</font><br>";
    print "<font class='text1'>Telefone:</font> <font class='texto'>$telefone</font><br>";
    print "<font class='text1'>Fax:</font> <font class='texto'>$fax</font><br>";
    print "<font class='text1'>Profiss&atilde;o:</font> <font class='texto'>$profissao</font><br>";
    print "<font class='text1'>Actividade:</font> <font class='texto'>$actividade</font><br>";
    print "<font class='text1'>Email:</font> <font class='texto'>$email</font><br>";
    print "<font class='text1'>Contribuinte nr&ordm;:</font> <font class='texto'>$nrcont</font><br>";
    print "<font class='text1'>Comentario:</font> <font class='texto'>$msg</font>";
    
    	$result = mysql_query("select * from cart where cookieId = '" . GetCartId() . "' order by cod asc");		
    	$num=mysql_num_rows($result);
    	print "<br><br><font color='#006633' class='text1'>Total de $num produtos no seu carrinho de compras.</font>";
    	print "<table width='100%' cellspacing='0' cellpadding='0' border='0'>";
    			print "<tr>";
    				print "<td width='28%' height='25' bgcolor='#CCCCCC'><div align='left'><span class='linkum'><font face='verdana' size='1' color='white'><b>C&oacute;digo</b></font></span></div></td>";
    				print"<td width='33%' bgcolor='#CCCCCC'><div align='left' class='linkum'>
    				  <div align='left' class='linkum'><font face='verdana' size='1' color='white'><b>Qtd</b></font></div>";
    				print"</div></td>";
    				print"<td width='33%' height='25' bgcolor='#CCCCCC'><div align='left'><font face='verdana' size='1' color='white'><b>Pre&ccedil;o uni.</b></font></div></td>";
    			print"<td width='25%' height='25' bgcolor='#CCCCCC'><div align='left'><span class='linkum'><font face='verdana' size='1' color='white'><b>Sub Total </b></font></span></div></td>";
    			print"</tr>";
    			
    			$total=0;
    			while($row = mysql_fetch_array($result))
    			{
    			$preco=$row['preco'];
    			$preco = str_replace(",",".",$preco);
    			$query1 = mysql_query("select * from sub_produto where id=$row[itemId]");
    			$dados = mysql_fetch_array($query1);
    			$total+=floatval($preco);
    			
    					print"<tr>";
    						print"<td width='28%' height='25' class='texto'><div align='left'> $row[cod] </div></td>";
    						print "<td width='33%' align='left' class='texto'><div align='left'> $row[qty]</div></td>";
    						print "<td width='33%' height='25' class='texto'><div align='left'>&euro; $dados[euro] </div></td>";
    						print"<td width='18%' height='25' class='texto'><div align='left'>&euro;$row[preco]</div></td>";
    						
    					print"</tr>";
    					print "<td colspan='4'><hr size='1' color='#CCCCCC' NOSHADE></td><br>";
    					
    	}	
    	
    	$total=str_replace(".",",",$total);
    	
    	print"<tr>";
    	print"<td colspan='3'><div align='right' class='text1'><strong>Total: &euro;$total<br><br><br><br></strong></div></td>";
    							
    					print"</tr>";		
    }		
    
    
    ?></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>
    
    PHP:
     
    afonseca, Nov 9, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your mailbody functions prints all the data rather than returning it so $Emailbody doesn't actually hold any value.

    Get rid of all the prints and just build a variable you return at the end of the function.
     
    T0PS3O, Nov 9, 2006 IP