Jump to content



Latest News: (loading..)

- - - - -

Weird problem. If you know what you're talking about, I need your help.


  • Please log in to reply
2 replies to this topic

#1   sammedit

sammedit
  • Members
  • 85 posts
  • Real Name:B
  • Gender:Male

Posted 23 August 2012 - 01:50 AM

Ok,
Here is what we have:

Problem:  Added code to html email addon file to get comments from the database to include in the email.  The code works great unless the comments field has returns in between text as you would use to start a new paragraph.  There are no html tags in the comments field.  

For example, if the comments field was:

In the latest promo for this year's awards show, the comedian storms in on an unwitting Swift, who's just sitting there playing her guitar and singing...you know, doing that regular old Taylor thing. "For the last time, stop writing songs about me," Hart snaps, explaining he is not about to be embarrassed on his big night hosting the VMAs . "I'm not going to go up there and be known as Mr. Ex-Taylor Swift!"

Then the email sends just fine.  But if the comments field is:

In the latest promo for this year's awards show, the comedian storms in on an unwitting Swift, who's just sitting there playing her guitar and singing...you know, doing that regular old Taylor thing.

"For the last time, stop writing songs about me," Hart snaps, explaining he is not about to be embarrassed on his big night hosting the VMAs .

"I'm not going to go up there and be known as Mr. Ex-Taylor Swift!"

It will return this error:


Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in catalog/admin/includes/classes/email.php on line 522

Warning: Cannot modify header information - headers already sent by (output started at /catalog/admin/includes/classes/email.php:522) in catalog/admin/includes/functions/general.php on line 100

The code I added to include the comments in the email is:

$check_comment_query = tep_db_query("select comments from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . (int)$oID . "'");
$check_comments = tep_db_fetch_array($check_comment_query);
$order_comments = $check_comments['comments'];

The html email file I added it to is:

<?php
/*
order_confirm.php, 2011
mail manager for oscommerce
Copyright (c) 2011 Niora http://www.css-oscommerce.com
Released under the GNU General Public License
*/
//get status of mail manager create account  email
$mail_manager_status_query = tep_db_query("select status, template, htmlcontent, txtcontent from  " . TABLE_MM_RESPONSEMAIL . "  where mail_id = '1'");
$mail_manager_status = tep_db_fetch_array($mail_manager_status_query);
//default to tep_mail if order_confirm mailpiece inactived in admin
if (isset($mail_manager_status['status']) && ($mail_manager_status['status'] == '1')) {  // create the order totals variable
   for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
	$mm_ordertotal .= strip_tags($order->totals[$i]['title']) . ' ' . strip_tags($order->totals[$i]['text']) . "\n";
  }
$header_query = tep_db_query("select htmlheader, htmlfooter, txtheader, txtfooter from " . TABLE_MM_TEMPLATES . " where title = '".$mail_manager_status['template']."'");
$header = tep_db_fetch_array($header_query);//build email
$output_content_html = $header['htmlheader'].$mail_manager_status['htmlcontent'].$header['htmlfooter'];
$output_content_txt = $header['txtheader'] . "\n\n" . $mail_manager_status['txtcontent'] . "\n\n" . $header['txtfooter'];
$output_subject = EMAIL_TEXT_CONFIRM;
[b]$check_comment_query = tep_db_query("select comments from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . (int)$oID . "'");
$check_comments = tep_db_fetch_array($check_comment_query);[/b]

//define values for placeholder variables
$order_no = EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID;
$order_date = EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG);
$invoice_url = EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL', false);
$delivery_address = tep_address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br />');
$billing_address = tep_address_format($order->billing['format_id'], $order->billing, 1, '', '<br />');
[b]$order_comments = $check_comments['comments'];[/b]
$paymentmethod = $order->info['payment_method'];
$ccardtype = $order->info['cc_type'];
$payment_class = $payment_class->email_footer;

//define placeholders
$placeholders=array('$storeurl', '$storename','$storeemail','$separator','$orderno','$orderdate','$invoiceurl','$productsorderedhead','$productsordered','$deliveryaddresshead','$deliveryaddress','$billingaddresshead', '$billingaddress', '$paymethodhead', '$paymentmethod', '$ccardtype','$ordercomments','$totaltext','subtotaltext', '$ordertotal');

$values=array(HTTP_SERVER,STORE_NAME,STORE_OWNER_EMAIL_ADDRESS,EMAIL_SEPARATOR, $order_no,$order_date, $invoice_url,EMAIL_TEXT_PRODUCTS,$products_ordered, EMAIL_TEXT_DELIVERY_ADDRESS,$delivery_address, EMAIL_TEXT_BILLING_ADDRESS, $billing_address, EMAIL_TEXT_PAYMENT_METHOD, $paymentmethod, $ccardtype, $order_comments, EMAIL_TEXT_TOTAL, EMAIL_TEXT_SUBTOTAL, nl2br($mm_ordertotal));

$output_content_html=str_replace($placeholders, $values, $output_content_html);
$output_content_txt=str_replace($placeholders, $values, $output_content_txt);

//send email	
tep_mm_sendmail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, $output_subject, $output_content_html, strip_tags($output_content_txt));
//if mail manager status update email 'inactive' process normally via oscommerce
}else{	
	tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
  }
?>

The code in catalog/admin/includes/classes/email.php on line 522 is:

return mail($to, $subject, $this->output, 'From: '.$from.$this->lf.implode($this->lf, $this->headers).$this->lf.implode($this->lf, $xtra_headers));

Any idea why having spaces in a db field would cause this much trouble?  I will gladly provide any more information to anyone who thinks they can help.  Thank you in advance.

sammedit

#2   MrPhil

MrPhil
  • Members
  • 4,194 posts
  • Real Name:Phil
  • Gender:Male

Posted 24 August 2012 - 01:31 AM

The mail protocol uses certain "end of line" conventions such as \r\n to separate sections of a mail message. It sounds like the hard coded breaks in your message are being interpreted as the starts of new sections or commands, and you get the errors. If your mail is not HTML, you may simply have to strip out whatever the line ends are, or maybe change them to some other form that doesn't trigger the mail command sections but still visually formats right. If your mail is HTML, you could replace the line ends by <br>'s.

#3   sammedit

sammedit
  • Members
  • 85 posts
  • Real Name:B
  • Gender:Male

Posted 27 August 2012 - 09:12 AM

@MrPhil

Hey Phil,
     Thank you for your help.  You were right and I had the answer before I wrote this post.  I just forgot to put the file after I made the change and then assumed it didn't work.  After reading your post I did it again and it worked perfectly.  Thank you!