6 Replies - 1508 Views - Last Post: 27 September 2011 - 07:24 AM Rate Topic: -----

#1 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Call to a member function ClearAttachments() on a non-object

Posted 26 September 2011 - 11:13 AM

Don't understand this error:
"Fatal error: Call to a member function ClearAttachments() on a non-object in /home/.../RGSTRTN_06_6.php on line 532" Last line of script

------------- script ------------------------------------------------------
// F. POST requested free
publications with phpmailer script  		//
$options  = array(
		  'USIT_ovr_En'=> "$USIT_ovr_En", 'USIT_ovr_Sp'=> "$USIT_ovr_Sp",
		  'NL01_10'    => "$EnNL01_10",   'SpNL01_19'  => "$SpNL01_19",   'NL11_20'=> "$EnNL11_20",
		  'SpNL01_54'  => "$SpNL01_54",   'NL21_30'    => "$EnNL21_30",   'NL31_40'=> "$EnNL31_40",
		  'NL41_50'    => "$EnNL41_50",   'NL51_60'    => "$EnNL51_60",   'NL61_70'=> "$EnNL61_70",
		  'NL71_80'    => "$EnNL71_80"
		 );

	$path = '../../../PHPfiles/NwsLtr/Nwsltr_pdfs/';
	$path_file	= "$path" . $k . ".pdf";
	
	$to_email = $sandboxRGSTRTN ? "ntelleck@u-sit.net" : "$email";
	
foreach($options as $k => $value)
       { 
	if($value)
		{
	$path_file = $sandboxRGSTRGN ? "$path" . "eUSIT1Sp"  . "pdf"
				     : "$path" . $k . ".pdf" ;
  $mail = new phpmailerlite(); 

  $message = "$time_stamp <p> Thank you for your interest in U-SIT. <p> 
				Your requested material is attached herewith.<p>";
  $body = preg_replace("[/]",'',$message);
  $mail -> SetFrom('name@domain.net, 'me');		
  $mail -> AddReplyTo('name@domain.net, 'me');	
  $mail -> MsgHTML($body);
  $mail -> AltBody = "To view the message, please use an HTML compatible email viewer!";
  $mail -> Subject = 'Your free USIT-HI literature order';

  $sndbxRGSTRTN ? $mail -> AddAddress('ntelleck@u-sit.net', "e. sickafus")
				: $mail -> AddAddress($email, $first_name. " " . $last_name); 
  $mail->AddAttachment("$path_file");   // attachment
	if(!$mail->Send()) 
			{
			echo ("Mailer error:  $mail->ErrorInfo <p>");
			fputs($fp1, "L. 530, Mail error:  $mail->ErrorInfo  \n");
			}
   	   else {   
			echo "Email Message sent. <p>";
			fputs($fp1, "L. 529, Mail sent \n");
			}	  
		}		// end of if($value)
       }		// end of foreach($options as $k => $value)
	$mail->ClearAttachments();

-----------------------------------------------------------------------------------------------
This script requires class.phpmailer-lite.php, which has the following declaration ...
  public function ClearAttachments() {
    $this->attachment = array();
  }


I suspect something wrong above the last line. Have checked matching {}, [], and () to no avail.

Any help will be appreciated.
thnx
USIT-HI

MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 26 September 2011 - 12:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Call to a member function ClearAttachments() on a non-object

#2 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Re: Call to a member function ClearAttachments() on a non-object

Posted 26 September 2011 - 11:59 AM

PS:
I modified a line in the script immediately following that shown above and got this error:
"Warning: fputs() expects parameter 1 to be resource, null given in /home/.../RGSTRTN_06_6.php on line 525" (on the 4th to last line in this snippet...

---------------------- scrip following that given above -------------------

}

If ($purchase && $validated)
{
?>

<form target="paypal"
action="https://www.<? sndbxRGSTRTN ? "sandbox."
: ""; ?> paypal.com/cgi-bin/webscr" method="post"/>
------------------------------------------------------------------------------------------
the line beginning <form was modified to that shown. Then the 2nd error was thrown (the 1st has yet to be corrected). The php snippet inserted into the html <form, didn't cause an error.

USIT-HI
Was This Post Helpful? 0
  • +
  • -

#3 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Re: Call to a member function ClearAttachments() on a non-object

Posted 26 September 2011 - 12:05 PM

NIX THAT!!
(I must be too tired)

The fput($fp1 ... error is 4 lines above the L. 532 shown in the first note #1.

It seems to come and go as I make test adjustments to that section of script.

Sorry for note #2 >.<
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: Call to a member function ClearAttachments() on a non-object

Posted 26 September 2011 - 12:29 PM

$mail is defined solely within your foreach block. Once you leave that block, it's gone...and you're calling that function outside of the block.

Time to read up on variable scope.
Was This Post Helpful? 1
  • +
  • -

#5 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Re: Call to a member function ClearAttachments() on a non-object

Posted 27 September 2011 - 06:42 AM

JackOfAllTrades
very helpful
a response with explanation is the most helpful response
thnx && thnx
USIT-HI
Was This Post Helpful? 0
  • +
  • -

#6 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Re: Call to a member function ClearAttachments() on a non-object

Posted 27 September 2011 - 07:14 AM

ref: L. 38 & L. 41 in #1 above.
Compiler likes the 1st fputs (L. 38) but not the 2nd (L. 38) [?] I've tried variations is typing the statement, including a completely fresh line. Nothing I've tried works.
any ideas appreciated

--------------- snippet from #1 above -----------------------------
	if(!$mail->Send()) 
			{
			echo ("Mailer error:  $mail->ErrorInfo <p>");
			fputs($fp1, "L. 530, Mail error,  $mail->ErrorInfo  \n");
			}
   	   else {   
			echo "Email Message sent. <p>";
			fputs($fp1, "L. 525, Mail sent \n");
			}


-------------------------------------------------------------
(Why me God? I've been good!)

thnx
USIT-HI

This post has been edited by macosxnerd101: 27 September 2011 - 09:49 AM
Reason for edit:: CODE TAGS!!! USE THEM!!!

Was This Post Helpful? 0
  • +
  • -

#7 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Re: Call to a member function ClearAttachments() on a non-object

Posted 27 September 2011 - 07:24 AM

FORGET IT!!
After retyping the full line again the compiler shut up!
I don't get it, but I'll take it.

thanx for listening
USIT-HI
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1