Warning: Illegal string offset 'over_email' in ifthd.php on line 1444

If someone could help me figure out what’s wrong I would be forever grateful. I am getting this error on a form that works (another one too, maybe I can post after for help with it). I have no idea about PHP. I did search for days and can’t figure out what’s wrong.

[php] $this->core->db->construct( array(
‘select’ => array( ‘id’, ‘name’, ‘email’, ‘email_html’ ),
‘from’ => ‘members’,
‘where’ => array( ‘id’, ‘=’, $member_id ),
‘limit’ => array( 0, 1 ),
) );

    $this->core->db->execute();

    if ( $this->core->db->get_num_rows() == 1 )
    {
        $mem = $this->core->db->fetch_row();

        if ( $extra['over_email'] )
        {
            $this->core->email->add_recipient( $extra['over_email'] );

            $replacements['MEM_EMAIL'] = $extra['over_email'];
        }
        else
        {
            $this->core->email->add_recipient( $mem['email'] );

            $replacements['MEM_EMAIL'] = $mem['email'];
        }[/php]

Where does the variable $extra come from? The code seem to assume it’s an array - while it’s really a string. You need to either fix it so it’s the array it expects, or change the code to use the string instead of an array.

I think this is where it comes from. How would I change it to a string? Thanks for responding!

[php] function send_email($recipient, $message, $replacements=’’, $extra=’’, $reply_line=0)
{
if ( ! is_array( $recipient ) )
{
$old_recp = $recipient;
unset( $recipient );

		$recipient[] = $old_recp;
	}

	$this->core->load_module('email');
	
	if ( $this->core->cache['config']['email_method'] == 'native' )
	{
		$email_int = array( 'method' => 'native' );
	}
	elseif ( $this->core->cache['config']['email_method'] == 'smtp' )
	{
		$email_int = array( 'method' => 'smtp', 'smtp_host' => $this->core->cache['config']['smtp_host'], 'smtp_port' => $this->core->cache['config']['smtp_port'], 'smtp_user' => $this->core->cache['config']['smtp_user'], 'smtp_pass' => $this->convert_html( $this->core->cache['config']['smtp_pass'] ), 'smtp_encrypt' => $this->core->cache['config']['smtp_encryption'] );[/php]

The code in the first post expects it to be an array, but it is a string.

The code in your second post is of a function that accepts a parameter with the same name ($extra), and it’s defaulted to be an empty string.

They seem to be contradicting eachother.

Is the code block in your first post from the same send_email function? If so, please post the entire function.

If not, we need more code, please try to find a natural “chop off” point around the code you posted in your first post.

This is the whole section. I get the same type of error from “if ( $extra[‘from_email’] )” at line 107. So the two problems are line 57 and 107.

[php] #=======================================
# @ Send Email
# Sends an email.
#=======================================

function send_email($recipient, $message, $replacements='', $extra='', $reply_line=0)
{
	if ( ! is_array( $recipient ) )
	{
		$old_recp = $recipient;
		unset( $recipient );

		$recipient[] = $old_recp;
	}

	$this->core->load_module('email');
	
	if ( $this->core->cache['config']['email_method'] == 'native' )
	{
		$email_int = array( 'method' => 'native' );
	}
	elseif ( $this->core->cache['config']['email_method'] == 'smtp' )
	{
		$email_int = array( 'method' => 'smtp', 'smtp_host' => $this->core->cache['config']['smtp_host'], 'smtp_port' => $this->core->cache['config']['smtp_port'], 'smtp_user' => $this->core->cache['config']['smtp_user'], 'smtp_pass' => $this->convert_html( $this->core->cache['config']['smtp_pass'] ), 'smtp_encrypt' => $this->core->cache['config']['smtp_encryption'] );
	}
	
	$this->core->email->initialize( $email_int );

	$langid = $this->member['lang'];
	if ( ! $langid ) $langid = $this->core->cache['lang']['default'];

	require HD_PATH. "language/". $langid ."/lang_email_content.php";

	while ( list( , $member_id ) = each( $recipient ) )
	{
		$this->core->db->construct( array(
									  	  'select'	=> array( 'id', 'name', 'email', 'email_html' ),
									  	  'from'	=> 'members',
									  	  'where'	=> array( 'id', '=', $member_id ),
									  	  'limit'	=> array( 0, 1 ),
							  	   ) 	 );

		$this->core->db->execute();

		if ( $this->core->db->get_num_rows() == 1 )
		{
			$mem = $this->core->db->fetch_row();

			if ( $extra['over_email'] )
			{
				$this->core->email->add_recipient( $extra['over_email'] );
				
				$replacements['MEM_EMAIL'] = $extra['over_email'];
			}
			else
			{
				$this->core->email->add_recipient( $mem['email'] );
				
				$replacements['MEM_EMAIL'] = $mem['email'];
			}

			$subject = $lang[ $message ."_sub" ];

			$replacements['MEM_NAME'] = $mem['name'];
			$replacements['MEM_ID'] = $mem['id'];
			$replacements['HD_NAME'] = $this->core->cache['config']['hd_name'];
			$replacements['HD_URL'] = $this->core->cache['config']['hd_url'];

			$email_msg = $lang['header'] ."\n\n" . $lang[ $message ] ."\n\n" . $lang['footer'];
			
			if ( $reply_line && $this->core->cache['config']['email_use_rline'] )
			{
				$email_msg = $this->core->cache['config']['email_reply_line'] ."\n\n". $email_msg;
			}

			foreach( $replacements as $search => $replace )
			{
				if ( $mem['email_html'] )
				{
					$replaceb = $replace;
				}
				else
				{
					$replaceb = preg_replace( "/<p>(.+?)<\/p>/", "$1\n\n", $this->convert_html( $replace ) );
					$replaceb = str_replace( '<br />', "\n", $replaceb );
				}

				$email_msg = str_replace( "<#". $search ."#>", $replaceb, $email_msg );
				$subject = str_replace( "<#". $search ."#>", $replace, $subject );
			}

			foreach ( $this->lang as $langkey => $langvalue )
			{
				$email_msg = str_replace("{lang.". $langkey ."}", $langvalue, $email_msg);
			}

			$config = array(
							'from_email'		=> $this->core->cache['config']['out_email'],
							'from_name'		=> $this->convert_html( $this->core->cache['config']['hd_name'] ),
							);

			if ( $extra['from_email'] )
			{
				$config['from_email'] = $extra['from_email'];
			}

			$this->core->email->update_config( $config );
		
			$this->core->email->set_subject( html_entity_decode( $subject, ENT_QUOTES, 'UTF-8' ) );
			
			if ( $mem['email_html'] )
			{
				$this->core->email->add_message( html_entity_decode( $this->convert_html( str_replace( '&nbsp;', " ", $email_msg ) ), ENT_QUOTES, 'UTF-8' ) );
			
				$this->core->email->add_message( html_entity_decode( $this->convert_html( nl2br( str_replace( '&nbsp;', " ", $email_msg ) ) ), ENT_QUOTES, 'UTF-8' ), 'text/html' );
			}
			else
			{
				$this->core->email->add_message( html_entity_decode( $this->convert_html( str_replace( '&nbsp;', " ", $email_msg ) ), ENT_QUOTES, 'UTF-8' ) );
			}

			$this->core->email->send_email();
			
			$this->core->email->flush();
		}
	}
}

[/php]

I question the quality of your code when you have a function without phpdoc and parameters that are default to the wrong type.

Anywho, it seems like this code somewhere is called without passing in an array as the 4th param

ie:
[php]send_email($recipient, $message, $replacements);[/php]

You just need to make sure you’re sending in an array as the 4th param ($extra), with the keys/values the function expects.

TL:DR
While the code you’ve pasted certainly have some odd quirks the errors mentioned are not in this function, but where this function is called. It seems to be called without spesifying the 4th param.

After I had posted this I read somewhere to add isset to it. It did make the errors stop and the form works as it always did (is this ok to do?). I don’t know much about PHP. My head hurts from trying to figure this out over the last few days. I will do some more digging another time and find where it’s called from to maybe fix it. Thanks so much for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service