我在相同的* .php文件中测试了代码并且它可以工作但是当我尝试将mail
函数放入单独的文件时,我收到错误。
档案1
<?php
include_once("settings.php");
include_once("include/frontend_functions.php");
include_once("include/login_functions.php");
include_once("include/email_functions.php");
include("include/session.php");
$poArgs = array(
'user_id' => $_SESSION['js_user_id'],
'order_id' => $_SESSION['order']['id'],
'subtotal' => $_SESSION['order']['quote']['subtotal'],
'tax' => $_SESSION['order']['quote']['tax'],
'secondary_tax' => $_SESSION['order']['quote']['secondary_tax'],
'soda_tax' => $_SESSION['order']['quote']['soda_tax'],
'tip' => $_SESSION['order']['quote']['tip'],
'discount' => $_SESSION['order']['quote']['coupon_amt'],
'total' => $_SESSION['order']['quote']['total'],
'payment_method' => $_POST['check_pay_method'],
'payment_collected' => 0,
);
$order_id = $_SESSION['js_user_id'];
if (function_exists('send_order_confirmation_email')){
send_order_confirmation_email($order_id);
}
else {
echo "$send_order_confirmation_email not defined";
}
?>
文件2(包含/ email_functions.php)
<?php
include_once("../settings.php");
include_once("frontend_functions.php");
include_once("login_functions.php");
include_once("order_functions.php");
include_once("jsmail.php");
function send_order_confirmation_email($order_id)
{
//send - only called if $placed!=0
global $db;
$order = $db->get_full_order_info_by_id($order_id);
$user = $db->get_user_info_by_id($order['user_id']);
$to_email = $user['email'];
$to_name = $user['fname'] . ' ' . $user['lname'];
$store = $db->get_store_location_by_id($order['store_id']);
$wait_time = $store['wait_time'];
//$wait_time = $db->get_store_waitime($order['store']['id']);
$from = $db->get_admin_content_by_code('notifications_email');
$fromname = '';
$subject = 'Thank You For Your Order!';
$html = "Your meal is being freshly prepared at our store <b><u>" . $store['name'] . "</u></b>.<br /><br />";
if ($order['delivery_type'] == 'D') {
$html .= "<span style='font-weight: bold; font-size:12px!important;'>Estimated delivery time is ". $wait_time . ".</span><br />";
$html .= "<br />
As soon as your order is on it's way, we will notify you via email. Stay tuned!";
} else {
$html .= "<span style='font-weight: bold; font-size:12px!important;'>Your order will be ready for pickup in " . $wait_time . ".</span><br />";
}
$html2 = "<table>
<tr>
<td>
<table width='100%'>
<tr style='font-size: 12px !important;'>
<th colspan='2' style='background: rgb(245,250,240);'>RECEIPT - ORDER #" . $order['oxid'] . " Order placed on " . date('m/d/y', strtotime($order['orderplaced_ts'])) . ', at ' . date('h:ia', strtotime($order['orderplaced_ts'])) . "</th>
</tr>
<tr style='font-size: 10px !important;'>
<td>";
if ($order['delivery_type'] == 'D') {
$html2 .= "<h3 style='font-size:12px!important; margin: 0;'>Deliver To:</h3>";
} else {
$html2 .= "<h3 style='font-size:12px!important; margin: 0;'>Pickup At:</h3>";
}
$html2 .= get_row($order['company'], '', '<br />') . "
" . get_row($order['address_1']) . "
" . get_row($order['address_2'], '', '', true) . "
" . get_row($order['address_3'], '', '', true) . "
" . get_row($order['city'], '', ',', true) . "
" . get_row($order['abbreviation'], ' ') . "
" . get_row($order['zip'], ' ') . "
" . get_row($order['phone'], '', '', true) . "
" . get_row($order['ext'], ' ext. ', '') . "
</td>
<td>" . get_row($order['comments'], "<h3 style='font-size:12px!important; margin: 0;'>Delivery Instructions:</h3>") . "</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellspacing='0'>
<tr style='font-size: 12px !important;'>
<th align='left' style='background: rgb(245,250,240);'>ITEM</th>
<th align='center' style='background: rgb(245,250,240);'>QTY</th>
<th align='center' style='background: rgb(245,250,240);'>PRICE</th>
</tr>";
if ($order) {
$item_ids = array();
foreach ($order['items'] as $item) {
if ($item['menuitem_id'] > 0) $item_ids[] = $item['menuitem_id'];
}
$db_items = $db->get_menuitem_list($item_ids);
$db_items = $db->get_id_keyed_array($db_items);
foreach ($order['items'] as $item) {
if ($item['quantity'] > 0) {
$html2 .= "<tr style='font-size: 10px !important;'>
<td align='left' style='border-bottom: 1px solid rgb(160,206,103); padding-top: 10px;'>";
if ($item['fav_id'] > 0) {
$fav = $db->get_favorite_by_id($item['fav_id']);
$html2 .= "<span style='font-weight: bold; font-size:12px!important;'>" . $fav['favorite_nickname'] . " (" . $db_items[$item['menuitem_id']]['name'] . ")</span><br />";
} else if ($item['menuitem_id']) {
$html2 .= "<span style='font-weight: bold; font-size:12px!important;'>" . $db_items[$item['menuitem_id']]['name'] . "</span><br />";
} else {
$html2 .= "<span style='font-weight: bold; font-size:12px!important;'>Custom Item</span><br />";
}
if ($item['customizations']) {
$html2 .= get_row(get_customization_list($item['customizations']));
}
$html2 .= get_row($item['whofor'], 'For: ');
if ($item['choppingpreference'] || $item['dressingpreference'] || $item['includebread'] || $item['specialrequest']) {
$html2 .= "<h4>Preferences</h4>
<ul>
" . get_row($item['choppingpreference'], '<li>Chopping Preference: ', '</li>') . "
" . get_row($item['dressingpreference'], '<li>Dressing Preference: ', '</li>') . "
" . get_row($item['includebread'], '<li>Include Bread: ', '</li>') . "
" . get_row($item['specialrequest'], '<li>Special Instructions: ', '</li>') . "
</ul>";
}
$html2 .= "</td>
<td align='center' valign='top' style='font-weight: bold; font-size:12px!important; border-bottom: 1px solid rgb(160,206,103); padding-top: 10px;'>" . $item['quantity'] . "</td>
<td align='center' valign='top' style='font-weight: bold; font-size:12px!important; border-bottom: 1px solid rgb(160,206,103); padding-top: 10px;'>" . CURRENCY . $item['quantity'] * $item['price'] . "</td>
</tr>";
}
}
}
$html2 .= "<tr style='font-size: 12px !important;'>
<td valign='top' style='padding-top: 10px;'>";
if ($order['payment_method']) {
$html2 .= "<h3 style='font-size:12px!important; margin: 0;'>Payment Info:</h3>";
if ($order['payment_method'] == 'Credit Card') {
if ($order['payment_details']) {
$html2 .= $order['payment_details'] . "<br />";
} else {
$html2 .= $order['payment_method'] . "<br />";
}
} else {
$html2 .= $order['payment_method'] . "<br />";
}
}
$html2 .= "<br />
<span style='color: rgb(255,139,60); font-weight: bold; font-style: italic; font-size:10px!important;'>For food delivery/pickup related issues, please call " . $db->get_store_phone($order['store_id']) . ". For billing questions, please contact " . $db->get_admin_content_by_code('billing_email') . "</span></td>
<td valign='top' style='font-weight: bold; padding-top: 10px;'>";
if ($order['subtotal']) {
$html2 .= "Subtotal:<br />";
}
// removed >0 if statement, screwed up placement of totals
if ($order['tip']) {
$html2 .= "Tip:<br />";
}
// added extra line break to match total currency
if ($order['tax'] > 0) {
$html2 .= "Tax:<br /><br />";
}
if ($order['shipping'] > 0) {
$html2 .= "Delivery Fee:<br />";
}
if ($order['total']) {
$html2 .= "Total:<br />";
}
$html2 .= "</td>
<td align='right' valign='top' style='font-weight: bold; padding-top: 10px;'>
" . get_row($order['subtotal'], CURRENCY) . "<br />
" . get_row($order['tip'], CURRENCY) . "<br />
" . (TAX == "YES" ? get_row($order['tax'], CURRENCY) : "") . "<br />
" . (SHIPPING == "YES" ? get_row($order['shipping'], CURRENCY) : "") . "<br />
" . get_row($order['total'], CURRENCY) . "<br />
</td>
</tr>
</table>
</td>
</tr>
</table>";
$plain = str_replace(array('<br />', '<strong>', '</strong>', '<ul>', '</ul>', '<li>', '</li>', '<table>', '</table>', '<tr>', '</tr>', '<td>', '</td>', '<th>', '</th>', '<h3>', '</h3>', '<h4>', '</h4>', '<span>', '</span>'), '', $html . $html2);
$plain = preg_replace(array('/<table.*?>/', '/<tr.*?>/', '/<th.*?>/', '/<td.*?>/', '/<h3.*?>/', '/<span.*?>/'), '', $plain);
//add in html2 + 1
$html_template = make_html_template('order_confirm', $html, $html2);
//only send this email IF the order has been fully processed, i.e. NOT while waiting for Level Up
multiMail(array('email' => $to_email, 'name' => $to_name), $subject, $plain, $html_template, array('email' => $from, 'name' => $fromname), array('email' => $from, 'name' => $fromname), array(array('email' => ORDER_BCC_EMAIL, 'name' => ORDER_BCC_EMAIL_NAME)));
}
?>
如果我将文件2中的功能放入文件1并替换功能调用,则会发送电子邮件。当我将函数分成新文件时,它会停止。
这个函数是在IF语句中调用的,但根据我的理解,这是完全合法的。我在IF声明之外尝试过但仍然出错。
我在这里缺少什么?
编辑:
错误代码:PHP致命错误:在第21行的/app/checkout-payment.php中调用未定义的函数send_order_confirmation_email()
另外,我删除了函数内部的所有内容以替换为:
function send_order_confirmation_email($order_id){
//send - only called if $placed!=0
echo $order_id;
return true;
}
电话失败了....我的电话是错的吗?