Fatal error: Call to undefined function (works within the same PHP but not when seperate)
I tested the code from within the same *.php file and it works but when I try to put mymail
function into a separate file, I get an error.
File 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";
}
?>
File 2 (include/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)));
}
?>
If I place the function from File 2 into File 1 and replace the function call, the email gets sent. When I separate the function into a new file, it stops.
This function is being called from within an IF statement, but from my understanding this is perfectly legal. I've tried outside the IF statement and still got an error.
What am I missing here?
EDIT:
error code: PHP Fatal error: Call to undefined function send_order_confirmation_email() in /app/checkout-payment.php on line 21
Also, I deleted everything inside the function to replace with:
function send_order_confirmation_email($order_id){
//send - only called if $placed!=0
echo $order_id;
return true;
}
And the call failed....Is my call wrong?