Update for PHP 5.6 - Email Template Error

46 views
Skip to first unread message

GVSANTOS Group

unread,
Jan 30, 2017, 10:30:11 AM1/30/17
to AgileBill OSS Billing
# Before the AgileBill update for php 5.6 email template file looked like this:

### Replace the $replace vars in the body and subject
while(list($key, $value) = each($replace))
{
  $E['subject']   = eregi_replace($key, $value, $E['subject']);
  $E['body_text'] = eregi_replace($key, $value, $E['body_text']);
  if(!empty($E['body_html']))
  $E['body_html'] = eregi_replace($key, $value, $E['body_html']);
}

In this situation the email template is sent successfully but the php function eregi_replace () is deprecated in php 5.6 and excluded in php 7.0

PHP Deprecated:  Function eregi_replace() is deprecated in /modules/email_template/email_template.inc.php on line 494, 495 e 497


# With the new version have this file:

### Replace the $replace vars in the body and subject
while(list($key, $value) = each($replace))
{
  $E['subject']   = preg_replace('@'.$key.'@i', $value, $E['subject']);
  $E['body_text'] = preg_replace('@'.$key.'@i', $value, $E['body_text']);
  if(!empty($E['body_html']))
  $E['body_html'] = preg_replace('@'.$key.'@i', $value, $E['body_html']);
}

In this situation the e-mail is sent without template without it and without message with the following error message:

PHP Warning:  preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in /modules/email_template/email_template.inc.php on line 494, 495 e 497


# Because some internet searches I tried to change the expression to preg_match

### Replace the $replace vars in the body and subject
while(list($key, $value) = each($replace))
{
  $E['subject']   = preg_match('@'.$key.'@i', $value, $E['subject']);
  $E['body_text'] = preg_match('@'.$key.'@i', $value, $E['body_text']);
  if(!empty($E['body_html']))
  $E['body_html'] = preg_match('@'.$key.'@i', $value, $E['body_html']);
}

In this situation the e-mail is sent without template subject and message 0 0 with the following error message:

PHP Warning:  preg_match() expects parameter 2 to be string, array given in /modules/email_template/email_template.inc.php on line 494 e 495

How can I fix this problem and have the emails being sent automatically as subjects and the body of the message?

Reply all
Reply to author
Forward
0 new messages