Gethro Posted October 16, 2008 Share Posted October 16, 2008 Hi all, I'm new to php and have been ripping my hair out all day trying to figure out why the mails from the following code won't send. I think it has something to do with the ini_set() but I'm not sure. Any help would be greatly appreciated. Thanks in advance. <?php ini_set("sendmail_from","[email protected]"); if (isset($_GET["order_placement_result"])) { $smarty->assign("order_id", $_SESSION["order_id"]); $smarty->assign("order_amount", $_SESSION["order_amount"]); $smarty->assign("main_content_template", "order_place.tpl.html"); $smarty->assign("order_is_placed", $_GET["order_placement_result"]); } else if (isset($_POST["complete_order"])) { $c = 0; if (isset($_SESSION["gids"])) for ($j=0; $j<count($_SESSION["gids"]); $j++) if ($_SESSION["gids"][$j]) $c += $_SESSION["counts"][$j]; if (isset($_SESSION["gids"]) && $c) { db_query("insert into ".ORDERS_TABLE." (order_time, cust_firstname, cust_lastname, cust_email, cust_country, cust_zip, cust_state, cust_city, cust_address, cust_phone) values ('".get_current_time()."','".$_POST["first_name"]."','".$_POST["last_name"]."','".$_POST["email"]."','".$_POST["country"]."','".$_POST["zip"]."','".$_POST["state"]."','".$_POST["city"]."','".$_POST["address"]."','".$_POST["phone"]."');") or die (db_error()); $oid = db_insert_id(); $k = 0; $products = array(); $adm = ""; for ($i=0; $i<count($_SESSION["gids"]); $i++) if ($_SESSION["gids"][$i]) { $q = db_query("SELECT name, Price, product_code FROM ".PRODUCTS_TABLE." WHERE productID='".$_SESSION["gids"][$i]."'") or die (db_error()); if ($r = db_fetch_row($q)) { $tmp = array( $_SESSION["gids"][$i], $r[0], $_SESSION["counts"][$i], ($_SESSION["counts"][$i]*$r[1])." ".$currency_iso_3, $r[2] ); $articul = trim($tmp[4]) ? "[".$tmp[4]."] " : ""; db_query("insert into ".ORDERED_CARTS_TABLE." (orderID, productID, name, Price, Quantity) values ('$oid', '".$tmp[0]."', '".$articul.$tmp[1]."', '".$r[1]."', '".$tmp[2]."');"); $products[] = $tmp; $k += $_SESSION["counts"][$i]*$r[1]; $adm .= $articul.$tmp[1]." (x".$tmp[2]."): ".$tmp[3]."\n"; } } $smarty_mail->assign("order_content", $products); $smarty_mail->assign("order_total", $k." ".$currency_iso_3); $smarty_mail->assign("order_id", $oid); $smarty_mail->assign("order_custname", $_POST["first_name"]." ".$_POST["last_name"]); $smarty_mail->assign("order_shipping_address", $_POST["address"]."\n".$_POST["city"]." ".$_POST["state"]." ".$_POST["zip"]."\n".$_POST["country"]); $_SESSION["order_id"] = $oid; $_SESSION["order_amount"] = $k; mail($_POST["email"], EMAIL_CUSTOMER_ORDER_NOTIFICATION_SUBJECT, $smarty_mail->fetch("order_notification.tpl.html"), "From: \"".CONF_SHOP_NAME."\"<".CONF_GENERAL_EMAIL.">\n".stripslashes(EMAIL_MESSAGE_PARAMETERS)."\nReturn-path: <".CONF_GENERAL_EMAIL.">"); $od = STRING_ORDER_ID.": $oid\n\n"; $adm .= "\n".CUSTOMER_FIRST_NAME." ".$_POST["first_name"]."\n".CUSTOMER_LAST_NAME." ".$_POST["last_name"]."\n".CUSTOMER_ADDRESS.": ".$_POST["country"].", ".$_POST["zip"].", ".$_POST["state"].", ".$_POST["city"].", ".$_POST["address"]."\n".CUSTOMER_PHONE_NUMBER.": ".$_POST["phone"]."\n".CUSTOMER_EMAIL.": ".$_POST["email"]; mail(CONF_ORDERS_EMAIL, EMAIL_ADMIN_ORDER_NOTIFICATION_SUBJECT, $od.$adm, "From: \"".CONF_SHOP_NAME."\"<".CONF_GENERAL_EMAIL.">\n".stripslashes(EMAIL_MESSAGE_PARAMETERS)."\nReturn-path: <".CONF_GENERAL_EMAIL.">"); unset($_SESSION["gids"]); unset($_SESSION["counts"]); header("Location: index.php?order_placement_result=1"); } else { header("Location: index.php?shopping_cart=yes"); } } ?> Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 Have you checked that the code with the mail() functions is actually executing? Are the conditional tests giving a TRUE value so that that code is executing? The code is using sessions. Is there a session_start() statement at the beginning of the code? Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/#findComment-667056 Share on other sites More sharing options...
Gethro Posted October 16, 2008 Author Share Posted October 16, 2008 Thanks for the quick reply. Have you checked that the code with the mail() functions is actually executing? Are the conditional tests giving a TRUE value so that that code is executing? The exact same script is functioning on 4 other sites hosted by the same company. Is there an easy way to test the mail() function? The code is using sessions. Is there a session_start() statement at the beginning of the code? That's all the code, so I don't think there is. Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/#findComment-667062 Share on other sites More sharing options...
Gethro Posted October 16, 2008 Author Share Posted October 16, 2008 I have just received a mail from the host.... The key points for php mailscripts on our systems are as follows : ini_set("sendmail_from", "[email protected]"); $to = '[email protected]'; // any valid email address, anywhere $from = '[email protected]'; // or any other valid mailbox on your domain $sender = '[email protected]'; // any other valid mailbox on your domain, must be prefixed by -f $subject = 'the subject of your email'; $message = 'the message you are sending'; $headers = 'Content-type: text/plain; charset=UTF-8'; To send the mail you then use this : mail($to, $subject, $message, $headers, $sender); Does that add any useful info? Thanks Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/#findComment-667066 Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 That cannot be all the code because in addition to using sessions it is using a smarty template and there is nothing in the posted code that creates an instant of the smarty class. Some of the information from your host is redundant and unused. The ini_set() statement sets up a default From: address that is used when you don't put a From: address into the header field. However, both of your mail() function calls contain a From: address in the header field. The $from variable the host mentions is not being used in the code he shows and the use of the $sender variable is redundant. Start troubleshooting by putting the following two lines immediately after your first opening <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/#findComment-667078 Share on other sites More sharing options...
Gethro Posted October 16, 2008 Author Share Posted October 16, 2008 Ok, I've done that, saved and uploaded. It displayed no errors when I ordered from the cart. Thanks Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/#findComment-667086 Share on other sites More sharing options...
Gethro Posted October 16, 2008 Author Share Posted October 16, 2008 The strange thing is, the other sites all function without the ini_set("sendmail_from","[email protected]"); line of code. ??? Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/#findComment-667097 Share on other sites More sharing options...
Gethro Posted October 16, 2008 Author Share Posted October 16, 2008 Anybody any ideas? I'm stumped Link to comment https://forums.phpfreaks.com/topic/128708-ini_set/#findComment-667109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.