Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8859349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:02:19+00:00 2026-06-14T15:02:19+00:00

What im trying to do is take a cart generated from a site, and

  • 0

What im trying to do is take a cart generated from a site, and have it get emailed. When i run my code, the function runs on the page and doesnt send through email, but it shows up correctly. I cant get the output of my function to store to a variable that will work in the email. Here is the code I have…

function emailcartview() {
$total=0;
$totalvalue=0;
foreach($_SESSION as $name => $value) {
    if ($value>0){
        if (substr($name, 0, 5)=='cart_'){
            $id = substr($name, 5, (strlen($name)-5));
            $get = mysql_query('SELECT id, name, cost, item_number FROM mydbname WHERE id='.mysql_real_escape_string((int)$id));


            $cart = array();
            while ($get_row = mysql_fetch_assoc($get)) {
                $cart[] = array(
                'hsid' => $get_row['id'],
                'cost' => $get_row['cost'],
            $cost = $get_row['cost'],
                'itemno' => $get_row['item_number'],
                'name' => $get_row['name'],
                'value' => $value,
                $sub = $value*$cost,
                $total += $sub,
                $totalvalue = $value,
                'realsub' => number_format($sub, 2),
                );

                }
                foreach($cart as $index => $record){
                    global $emailcart;
                    $emailcart = "Item: {$record['itemno']} - {$record['name']} | Qty: {$record['value']} | Cost: {$record['cost']} x {$record['value']} = {$record['realsub']} <br>";
                    echo $emailcart;


            }

        }

    }

}
echo "Total : $".number_format($total, 2);
 }


$emailSubject = 'Invoice Submission';
$webMaster = 'my_email@blahblah.com';


$companyName = $_POST['companyname'];
$contactName = $_POST['contactname'];
$contactEmail = $_POST['contactemail'];
$teleNumber = $_POST['telenumber'];
$billAddr = $_POST['billaddr'];
$shipAddr = $_POST['shipaddr'];
$neededBy = $_POST['neededby'];
$cartprint .= emailcartview();

$body = "
<br><hr><br>
Company Name: $companyName <br>
Contact Name: $contactName <br>
Contact Email: $contactEmail <br>
Telephone Number: $teleNumber <br>
Billing Address: $billAddr <br>
Shipping Address: $shipAddr <br>
Date Needed: $neededBy <br> <br>
<br><hr><br>
$cartprint";

$headers = "From: ordersubmission@blahblah.com\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

 ?>

There are probably quite a few remnants of strange things ive tried and havent worked, not the cleanest. Any assistance would be greatly appreciated!!

Tylor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:02:20+00:00Added an answer on June 14, 2026 at 3:02 pm

    In function emailcartview you need to generate string rather than echo statement and at the end of function you should return that string.

    Check below code:

    function emailcartview() {
    $total=0;
    $totalvalue=0;
    $str = '';
    foreach($_SESSION as $name => $value) {
        if ($value>0){
            if (substr($name, 0, 5)=='cart_'){
                $id = substr($name, 5, (strlen($name)-5));
                $get = mysql_query('SELECT id, name, cost, item_number FROM mydbname WHERE id='.mysql_real_escape_string((int)$id));
    
    
                $cart = array();
                while ($get_row = mysql_fetch_assoc($get)) {
                    $cart[] = array(
                    'hsid' => $get_row['id'],
                    'cost' => $get_row['cost'],
                $cost = $get_row['cost'],
                    'itemno' => $get_row['item_number'],
                    'name' => $get_row['name'],
                    'value' => $value,
                    $sub = $value*$cost,
                    $total += $sub,
                    $totalvalue = $value,
                    'realsub' => number_format($sub, 2),
                    );
    
                    }
                    foreach($cart as $index => $record){
                        global $emailcart;
                        $str. = "Item: {$record['itemno']} - {$record['name']} | Qty: {$record['value']} | Cost: {$record['cost']} x {$record['value']} = {$record['realsub']} <br>";
    
                }
    
            }
    
        }
    
    
    }
    $str. = "Total : $".number_format($total, 2);
    return $str;
     }
    
    
    $emailSubject = 'Invoice Submission';
    $webMaster = 'my_email@blahblah.com';
    
    
    $companyName = $_POST['companyname'];
    $contactName = $_POST['contactname'];
    $contactEmail = $_POST['contactemail'];
    $teleNumber = $_POST['telenumber'];
    $billAddr = $_POST['billaddr'];
    $shipAddr = $_POST['shipaddr'];
    $neededBy = $_POST['neededby'];
    $cartprint .= emailcartview();
    
    $body = "
    <br><hr><br>
    Company Name: $companyName <br>
    Contact Name: $contactName <br>
    Contact Email: $contactEmail <br>
    Telephone Number: $teleNumber <br>
    Billing Address: $billAddr <br>
    Shipping Address: $shipAddr <br>
    Date Needed: $neededBy <br> <br>
    <br><hr><br>
    ".emailcartview();
    
    $headers = "From: ordersubmission@blahblah.com\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($webMaster, $emailSubject, $body, $headers);
    
     ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am trying to take my exciting wordpress blog from a live site
I am trying to take the base URL from a site and be able
I have a datagridview with 9 columns. I am simply trying take the value
I am trying to take the user to login page after cookies are cleared.
net I am trying to take a value from a previous form typically in
im trying to take std::string value and use it as delimiter in std::getline() function
I'm trying to take an existing php file which I've built for a page
So I'm trying to take a variable size (anywhere from a few MBs to
I'm trying to add a bundled item to the cart from the upsell area
Trying to take in several file names from the user at the command line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.