私はウェブショップをやっていて、カートをメールで受け取る必要があるときに立ち往生しています。カート機能を呼び出してメールで受け取る方法がわからないか、間違った機能を実行してメールでカートを受け取ります
function cart1(){
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, price FROM products WHERE id='.mysql_real_escape_string($id));
//racuna kolko kosta
while($get_row = mysql_fetch_assoc($get)){
$sub = $get_row['price']*$value;
echo $get_row{'name'}.' x '.$value.' Kom'.' = '.number_format($sub,2). ' kn';
}
}
//zbraje 1 i 2i ... proizvod
echo "<br />";
$total += $sub;
//echo "<hr width='150'>";
}
}
if ($total==0){
echo "Cart is empty.";
}
else{
echo 'Total: '.number_format($total, 2).' kn';
}
}
そしてメール機能、顧客情報を取得しましたが、機能の呼び出し方法がわかりません
<?php
require 'cart.php';
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "aaaa@hotmail.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Molimo Vas da upisete sva polja koja su oznacena *.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['adress']) ||
!isset($_POST['post']) ||
!isset($_POST['city']) ||
!isset($_POST['email']) ||
!isset($_POST['tel']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$adress = $_POST['adress']; // required
$post = $_POST['post']; // not required
$city = $_POST['city']; // required
$email = $_POST['email'];
$tel = $_POST['tel'];
$comments = $_POST['comments'];
$cart1 .= cart1();
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'U didnt write email..<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'Niste upisali Ime i Prezime.<br />';
}
if(!preg_match($string_exp,$oib)) {
$error_message .= 'Niste upisali OIB.<br />';
}
if(!preg_match($string_exp,$adress)) {
$error_message .= 'U didnt write adress.<br />';
}
if(!preg_match($string_exp,$post)) {
$error_message .= 'U didnt write Post number.<br />';
}
if(!preg_match($string_exp,$city)) {
$error_message .= 'U didnt write city.<br />';
}
if(!preg_match($string_exp,$tel)) {
$error_message .= 'U didnt write Tel.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'U didnt write comment.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First name/lastname: ".clean_string($name)."\n";
$email_message .= "Adres: ".clean_string($adress)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "Post: ".clean_string($post)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Tel: ".clean_string($tel)."\n";
$email_message .= "Fax: ".clean_string($fax)."\n";
$email_message .= "Comment: ".clean_string($comments)."\n";
$email_message = cart1();
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Tenx to buying here!<br />
<?php
}
?>