X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Email cart contents? (https://forum.x-cart.com/showthread.php?t=49659)

info@sjidesign.com 09-13-2009 05:18 AM

Email cart contents?
 
Hi,

I need to use "Email us for shipping costs" on a site for any country outside the UK.

For anyone outside the UK I have not put any shipping costs into my xcart admin.

The user goes through to the basket and sees the message "Before we can process your order we need to work out your shipping costs." which is fine.

I need for the to somehow be able to send me an email with their cart contents so that I can work out their shipping can this be done? ie I don not want them to have to type out everything in their basket just press a button and I get a copy of the products.

Thanks in advance

Dan

ElegantXMods.com 09-14-2009 03:38 AM

Re: Email cart contents?
 
Do you have any PHP experience?

If so, you could create a PHP page on the site root, say called emailcart.php - in this, the first lines would read

<?php
require "./auth.php";
x_load("cart");

This will give you access to the $cart variable, then just loop through $cart["products"], writing the details to a table, then use some of the other $cart variables to put in total, taxes, discounts etc. then wrap that whole string up into PHP's mail function and send it off to your address.

Then simply use JavaScript so that when someone clicks on that button, a popup box appears with emailcart.php loaded. Use JavaScript within emailcart.php to close the popup window when the page has fully loaded (i.e. the mail has been sent).

Does this make sense?

info@sjidesign.com 09-14-2009 04:23 AM

Re: Email cart contents?
 
Thank you very much for the reply.

Not sure I understand the following:

This will give you access to the $cart variable, then just loop through $cart["products"], writing the details to a table, then use some of the other $cart variables to put in total, taxes, discounts etc. then wrap that whole string up into PHP's mail function and send it off to your address.

The other parts make sense.

Thank you again, this is very helpful.

Regards

Dan

info@sjidesign.com 09-14-2009 04:28 AM

Re: Email cart contents?
 
Sorry to bother you again but how would the script be written to email the cart contents straight through to the email address info@test.com.

ElegantXMods.com 09-14-2009 04:50 AM

Re: Email cart contents?
 
Not tested this, but it should be pretty close to what you want:

<?php
require "./auth.php";
x_load('cart');

$html = "
<body>
<h2>Date: ". date(DATE_RFC822) ."</h2>

<table>
<tr>
<th>Product Code</th>
<th>Product Name</th>
<th>Price (". $config["General"]["currency_symbol"] .")</th>
<th>Qty</th>
<th>Subtotal (". $config["General"]["currency_symbol"] .")</th>
</tr>";

for ($i = 0; $i < $cart["max_cartid"]; $i++){
$html .= "<tr>
<td>". $cart["products"][$i]["productcode"] ."</td>
<td>". $cart["products"][$i]["product"] ."</td>
<td>". $cart["products"][$i]["price"] ."</td>
<td>". $cart["products"][$i]["amount"] ."</td>
<td>". $cart["products"][$i]["display_subtotal"] ."</td>
</tr>";
}

$html .= "</table>
<table>
<tr>
<td>Subtotal (". $config["General"]["currency_symbol"] .")</td>
<td>". $cart["subtotal"] ."</td>
</tr>
<tr>
<td>Discount (". $config["General"]["currency_symbol"] .")</td>
<td>". $cart["discount"] ."</td>
</tr>
<tr>
<td>Taxes: (". $config["General"]["currency_symbol"] .")</td>
<td>". $cart["tax_cost"] ."</td>
</tr>
<tr>
<td><b>Total (". $config["General"]["currency_symbol"] .")</b></td>
<td><b>". $cart["display_discounted_subtotal"] ."</b></td>
</tr>
</table>
</body>";

mail ("from@domain.com", "to@domain.com", "Subject Line", $html);

?>

info@sjidesign.com 09-14-2009 05:17 AM

Re: Email cart contents?
 
Thanks very much,

Just tried it out.

created a new page called emailcart.php and put this in my xcart directory root directory along with the home.php, cart.php etc.)

Copied the code you kindly wrote below into emailcart.php and put the file over.

Then made a link on my cart.php page to open up mydomain/shop/emailcart.php in a blank window, the page opens up but it is completely blank. There is nothing at all on the page.

Any ideas?

I'm sorry to keep on bothering you but i'm not that experienced with this code.

Sorry

Thank you for your patience and help, it is very much appreciated.

Regards

Dan

ElegantXMods.com 09-14-2009 05:45 AM

Re: Email cart contents?
 
The page itself won't show anything, all it does is put together a bunch of text and mails it out.

A few tips:

If there are no error messages, then the mail may have been sent correctly, did you remember to change 'to@domain.com'?

Have you got Firebug and Firefox? Did the page request come back with 200 OK or 500 Internal Server Error?

info@sjidesign.com 09-14-2009 06:09 AM

Re: Email cart contents?
 
yes, I did change the email address to the one I wanted.

Just cannot get it to work for some reason.

I cannot see any button/link to close the window and also no email whatsoever comes back to me :-(

Regards

Dan

ElegantXMods.com 09-14-2009 07:33 AM

Re: Email cart contents?
 
Hi Dan,

Unfortunately I don't have the time at present to debug this for you. Have you tried the following?
  • Echo $html to see what it's generating?
  • Determined if the page is coming back with a 500 Internal Server Error
  • Enabled full error reporting for that page to see any errors?
  • Checked the mail function - http://uk.php.net/manual/en/function.mail.php - a quick look here would tell you i messed up the syntax od the mail function. Again, because I'm pretty much doing this from memory, so you'll need to do some error checking before it works correctly.

ElegantXMods.com 09-14-2009 09:12 AM

Re: Email cart contents?
 
Any luck with this?

I'm sure it's just a typo - did you manage to add error reporting to the page?

info@sjidesign.com 09-14-2009 11:00 AM

Re: Email cart contents?
 
Got a little bit further, managed to get the email sending the product code and price through to me now :-)

Would you know how to get the customers email address and their shipping address on the email that comes throught to me? and also if I could get the email to come FROM the customer so that I can reply directly to it?

many thanks for your help, I am nearly there now.

Regards

Dan


<?php
require "./auth.php";
x_load('cart');

$emailSentTo = "info@here.com";
$subjectOfEmail = "Catac Shipping Quote";

//========= no need to edit bellow

// Set HTML Mail Header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// The Message
$message = $GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"];

//Cleaning Message

for ($i = 0; $i < $cart["max_cartid"]; $i++){


$message = $cart["products"][$i]["productcode"];
$message3 = $cart["products"][$i]["product"];
$message2 = $cart["display_discounted_subtotal"];


}
// Sending
mail($emailSentTo, $subjectOfEmail, $message, $message2, $headers);

//Thanking
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('Thank You, We will contact you shortly.');
window.location = \"http://$_SERVER[HTTP_HOST]\";
</script>
";
?>

info@sjidesign.com 09-22-2009 01:41 AM

Re: Email cart contents?
 
nearly done this now and works quite well :-)

Just need 2 things:

the product options (ie size or colour chosen) to show on my email (everything else such as item ordered, code etc. does)

and 2 my Email is coming back FROM Apache in the header, need somehow to either make the users email appear in the FROM header or just to show FROM Your Site.

Anyone got any ideas?

Regards

Dan

THIS IS THE CODE THAT IS WORKING WELL.


<?php
require "./auth.php";
x_load('cart','user','order','tests');
require $xcart_dir."/include/cart_process.php";
include $xcart_dir."/shipping/shipping.php";

$smarty->assign("register_script_name",(($config["Security"]["use_https_login"] == "Y") ? $xcart_catalogs_secure["customer"]."/" : "")."cart.php");
#
# Register member if not registerred yet
# (not a newbie - do not show help messages)
#
if ($mode == "checkout" && !$func_is_cart_empty) {
$usertype = "C";
$old_action = $action;
$action = "cart";
$smarty->assign("action", $action);
$newbie = "Y";
if (empty($login))
include $xcart_dir."/include/register.php";

if (!empty($auto_login)) {
func_header_location("cart.php?mode=checkout&regis tered=");
}

$saved_userinfo = isset($userinfo) ? $userinfo : array();
$action = $old_action;
$smarty->assign("newbie", $newbie);
}

if (!empty($login))
$userinfo = func_userinfo($login, $current_area, false, false, "H");
x_session_save();




$emailSentTo = "info@uorsite.com";
$subjectOfEmail = "Catac Shipping Quote";

//========= no need to edit bellow

// Set HTML Mail Header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// The Message
$message = $GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"];

//Cleaning Message

$message .= "Products Required";
$message .= "\n\n";
for ($i = 0; $i < $cart["max_cartid"]; $i++){
$message .= "Product Name: ";$message .= $cart["products"][$i]["product"];
$message .= "\n";
$message .= "Product Code: ";$message .= $cart["products"][$i]["productcode"];
$message .= "\n";
$message .= "Quantity: ";$message .= $cart["products"][$i]["amount"];
$message .= "\n\n";
}
$message .= "Cost of products BEFORE SHIPPING: ";$message .= $cart["subtotal"];

$message2 .= "\n";
$message2 .= "Customer Details & Address Items to be Shipped to";
$message2 .= "\n\n";
$message2 .= "Name: ";$message2 .= $userinfo["b_firstname"];
$message2 .= $userinfo["b_lastname"];
$message2 .= "\n";
$message2 .= "Email: ";$message2 .= $userinfo["email"];
$message2 .= "\n\n";
$message2 .= "City: ";$message2 .= $userinfo["b_city"];
$message2 .= "\n";
$message2 .= "Country: ";$message2 .= $userinfo["b_countryname"];
$message2 .= "\n";
$message2 .= "Post code: ";$message2 .= $userinfo["b_zipcode"];
$message2 .= "\n\n";



// Sending
mail($emailSentTo, $subjectOfEmail, $message, $message2, $headers);

//Thanking
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('Thank you for enquiring about our products, we will contact you shortly with your shipping costs.');
window.close();
</script>
";
?>

amy2203 09-22-2009 02:11 AM

Re: Email cart contents?
 
you need to specify the from header for the email, see here for help,

http://uk3.php.net/manual/en/function.mail.php

info@sjidesign.com 09-22-2009 02:57 AM

Re: Email cart contents?
 
Thanks for the reply, but this is not working.

I think it's because I have 5 parts in the mail code below (ie an extra $message):

mail($emailSentTo, $subjectOfEmail, $message, $message2, $headers);

I can get it working when I take out $message2 and leave 4 parts in the header.

I really need all 5, any ideas?

Regards

Dan

amy2203 09-22-2009 03:18 AM

Re: Email cart contents?
 
the mail function:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

so you have:
$emailsentto as $to
$subjectOfEmail as $subject
$message as $message
$message2 as $additionalheaders
$headers as $additionalparameters

so your $message2 is moving all of the parameters into the wronf places which is why it doesn't work with it in, but it does without it. You need to combine your $message and $message2 into a single variable to be passed to the mail function.

Try changing to:

Code:

//Cleaning Message

$message .= "Products Required";
$message .= "\n\n";
for ($i = 0; $i < $cart["max_cartid"]; $i++){
$message .= "Product Name: ";$message .= $cart["products"][$i]["product"];
$message .= "\n";
$message .= "Product Code: ";$message .= $cart["products"][$i]["productcode"];
$message .= "\n";
$message .= "Quantity: ";$message .= $cart["products"][$i]["amount"];
$message .= "\n\n";
}
$message .= "Cost of products BEFORE SHIPPING: ";$message .= $cart["subtotal"];

$message .= "\n";
$message .= "Customer Details & Address Items to be Shipped to";
$message .= "\n\n";
$message .= "Name: ";$message2 .= $userinfo["b_firstname"];
$message .= $userinfo["b_lastname"];
$message .= "\n";
$message .= "Email: ";$message2 .= $userinfo["email"];
$message .= "\n\n";
$message .= "City: ";$message2 .= $userinfo["b_city"];
$message .= "\n";
$message .= "Country: ";$message2 .= $userinfo["b_countryname"];
$message .= "\n";
$message .= "Post code: ";$message2 .= $userinfo["b_zipcode"];
$message .= "\n\n";


you can only assign 1 variable to be the actual message.


All times are GMT -8. The time now is 12:35 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.