Avatar billede andhansen Nybegynder
25. april 2003 - 17:23 Der er 10 kommentarer

PHP: mail() info fra textfields?

Jeg har lavet en side hvor jeg har brugt mail() funktionen og nu vil jeg gerne ha noget info fra brugeren, derfor har jeg lavet nogen textfields... mit problem er at jeg ikke kan få info'en sendt med i emailen... her er noget af koden:

    function sendmail()
    {
    $conn = mysql_connect("localhost", "ftpside", "xtP0m2UQNE9NT0W");
    mysql_select_db("ftpside");
        $sql = "select ii.itemName as navn, ii.Size as size, tt.qty as antal, (ii.Size * tt.qty) as ialt from cart tt, items ii where tt.cookieId='".GetCartId(). "' and tt.itemId=ii.itemId";
        $result = mysql_query($sql);
        $email = $_GET['email'];
        $content = "User: $user\nEmail: $email\n\n";
        while($row=mysql_fetch_array($result))
        {       
        $content .= "Name:" .$row[navn]."\nSize: ".$row[size]." mb\n\n";
        }
        mail("andreas@hansen.tdcadsl.dk","Request", $content);
    }

og noget af formularen:

<form name="frmCart" method="get" action="send.php">
        <p align="center"><strong>User:</strong><br>
          <input name="user" type="text" id="user">
          <br>
          <strong>Email:</strong><br>
          <input name="email" type="text" id="email">

jeg har spurt htm i dette spm: http://www.eksperten.dk/spm/208139, men han kunne desværre ikke hjælpe.

Jeg håber I kan..
Avatar billede Slettet bruger
25. april 2003 - 17:41 #1
Ikke helt med på hvad du mener... men er det ikke bar noget i den her stil??

$email = $_GET['email'];
$user = $_GET[user];
$content = "User: $user\nEmail: $email\n\n";
Avatar billede andhansen Nybegynder
25. april 2003 - 17:48 #2
det virkede ikke.... det var også det som htm forslog i det andet spm! ...men jeg er klar til at prøve flere ideer hvis du har...
Avatar billede andhansen Nybegynder
25. april 2003 - 17:48 #3
vil du ha hele koden?
Avatar billede andhansen Nybegynder
25. april 2003 - 17:59 #4
her er den:

<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<?php

    include("db.php");
       
    switch($_GET["action"])
    {
        case "add_item":
        {
            AddItem($_GET["id"], $_GET["qty"]);
            ShowCart();
            break;
        }
        case "update_item":
        {
            UpdateItem($_GET["id"], $_GET["qty"]);
            ShowCart();
            break;
        }
        case "remove_item":
        {
            RemoveItem($_GET["id"]);
            ShowCart();
            break;
        }
        case "confirm"://SEND MAIL
        sendmail();
        break;
        default:
        {
            ShowCart();
        }
    }

    function AddItem($itemId, $qty)
    {
        // Will check whether or not this item
        // already exists in the cart table.
        // If it does, the UpdateItem function
        // will be called instead
       
        global $dbServer, $dbUser, $dbPass, $dbName;

        // Get a connection to the database
        $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
       
        // Check if this item already exists in the users cart table
        $result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
        $row = mysql_fetch_row($result);
        $numRows = $row[0];
       
        if($numRows == 0)
        {
            // This item doesn't exist in the users cart,
            // we will add it with an insert query

            @mysql_query("insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)");
        }
        else
        {
            // This item already exists in the users cart,
            // we will update it instead
           
            UpdateItem($itemId, $qty);
        }
    }
   
    function UpdateItem($itemId, $qty)
    {
        // Updates the quantity of an item in the users cart.
        // If the qutnaity is zero, then RemoveItem will be
        // called instead

        global $dbServer, $dbUser, $dbPass, $dbName;

        // Get a connection to the database
        $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
       
        if($qty == 0)
        {
            // Remove the item from the users cart
            RemoveItem($itemId);
        }
        else
        {
            mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId");
        }
    }
   
    function RemoveItem($itemId)
    {
        // Uses an SQL delete statement to remove an item from
        // the users cart

        global $dbServer, $dbUser, $dbPass, $dbName;

        // Get a connection to the database
        $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
       
        mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
    }
   
    function sendmail()
    {
    $conn = mysql_connect("localhost", "ftpside", "xtP0m2UQNE9NT0W");
    mysql_select_db("ftpside");
        $sql = "select ii.itemName as navn, ii.Size as size, tt.qty as antal, (ii.Size * tt.qty) as ialt from cart tt, items ii where tt.cookieId='".GetCartId(). "' and tt.itemId=ii.itemId";
        $result = mysql_query($sql);
        $email = $_GET['email'];
        $user = $_GET[user];
        $content = "User: $user\nEmail: $email\n\n";
        while($row=mysql_fetch_array($result))
        {       
        $content .= "Name:" .$row[navn]."\nSize: ".$row[size]." mb\n\n";
        }
        mail("andreas@hansen.tdcadsl.dk","Request", $content);
    }
   
    function ShowCart()
    {
        // Gets each item from the cart table and display them in
        // a tabulated format, as well as a final total for the cart
       
        global $dbServer, $dbUser, $dbPass, $dbName;

        // Get a connection to the database
        $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
       
        $totalCost = 0;
        $result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc");
        ?>
        <html>
        <head>
        <title> Your Shopping Cart </title>
        <script language="JavaScript">
       
            function UpdateQty(item)
            {
                itemId = item.name;
                newQty = item.options[item.selectedIndex].text;
               
                document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
            }
       
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
        <body bgcolor="#666666" text="#000000" link="#000000" vlink="#000000" alink="#000000">
        <h1>&nbsp;</h1>
        <form name="frmCart" method="get" action="send.php">
        <p align="center"><strong>User:</strong><br>
          <input name="user" type="text" id="user">
          <br>
          <strong>Email:</strong><br>
          <input name="email" type="text" id="email">
    </p>
        <table width="37%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#999999">
            <tr bgcolor="#999999">
                <td height="25" bgcolor="#999999">
                    <font face="verdana" size="1" color="#000000">
                        <b>Product</b>
                    </font>                </td>
                <td width="15%" height="25">
                    <font face="verdana" size="1" color="#000000">
                        <b>Size:</b></font>
                </td>
                <td width="29%" height="25" bgcolor="#999999">
                    <font face="verdana" size="1" color="#000000">
                        <b>Remove?</b>
                    </font>
                </td>
            </tr>
            <?php
           
            while($row = mysql_fetch_array($result))
            {
                // Increment the total cost of all items
                $totalCost += ($row["qty"] * $row["Size"]);
                ?>
                    <tr>
                        <td height="25">
                            <font face="verdana" size="1" color="black">
                                <?php echo "<a href=\"#\" onClick=MM_openBrWindow('movie_info.php?filmid=$row[itemId]','','width=450,height=300')>$row[itemName]</a>"; ?>
                            </font>                        </td>
                        <td width="15%" height="25">
                            <font face="verdana" size="1" color="black">                                <?php echo number_format($row["Size"], 2, ".", ","); ?> mb                            </font>
                        </td>
                        <td width="29%" height="25">
                            <font face="verdana" size="1" color="black">
                                <a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a>
                            </font>
                        </td>
                    </tr>
                <?php
            }
           
            // Display the total
            ?>
                    <tr>
                        <td width="56%">
                            <font face="verdana" size="1" color="black">
                                <a href="products.php">&lt;&lt; Keep Shopping</a>
                            </font>
                        </td>
                        <td colspan="2">
                            <p><font face="verdana" size="2" color="black">
                                <b><?php echo number_format($totalCost, 2, ".", ","); ?></b><strong> mb    </strong> </font>
                              </p></td>
                    </tr>
          </table>
                <div align="center"></div>
                <div align="center"></div>
                <p align="center"><a href="cart.php?action=confirm"><strong>Send Request</strong></a></p>
        </form>
        </body>
</html>
            <?php
    }
?>
Avatar billede Slettet bruger
25. april 2003 - 18:08 #5
<p align="center"><a href="cart.php?action=confirm"><strong>Send Request</strong></a></p>
skal ændres til
<p align="center"><a href="java script:document.forms.frmCart.submit();"><strong>Send Request</strong></a></p>

og
<form name="frmCart" method="get" action="send.php">
til
<form name="frmCart" method="get" action="cart.php?op=confirm">

Så skulle det ovenover, meg $_GET virke!
Avatar billede andhansen Nybegynder
25. april 2003 - 18:20 #6
nu sender den ikke nogen email...
Avatar billede Slettet bruger
25. april 2003 - 18:23 #7
Så ændre det tilbage...
Hovedsagen er at du ikke overfører nogle info om brugeren nå du trykker på nedenstående link....
"><a href="cart.php?action=confirm"><strong>Send Request</strong></a></
Jeg har desværre ikke tid til mere...
Avatar billede andhansen Nybegynder
25. april 2003 - 18:25 #8
det er når jeg ændre
<form name="frmCart" method="get" action="send.php">
til
<form name="frmCart" method="get" action="cart.php?op=confirm">

så sender den ikke en mail... men den kan godt hvis jeg kun ændre
<p align="center"><a href="cart.php?action=confirm"><strong>Send Request</strong></a></p>
skal ændres til
<p align="center"><a href="java script:document.forms.frmCart.submit();"><strong>Send Request</strong></a></p>
Avatar billede Slettet bruger
25. april 2003 - 19:38 #9
så brug den sidste?
Virker det så også fint med det resterende... altså at få sendt navn og email adresse?
Avatar billede andhansen Nybegynder
05. december 2003 - 14:36 #10
tak for hjælpen... læg et svar hvis du vil ha point...
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester