Click to See Complete Forum and Search --> : Need help with OOP


Natcon67
09-20-2005, 12:16 AM
Hello all,
I am having a problem with calling a method in a class.
The error i am getting is "Call to a member function on a non-object".
and it referrs to the second line in the included notification.php.
The method in the class exists and here is the code:



require('../../mail/class.phpmailer.php');
$result = mysql_query("SELECT * FROM logins WHERE email = '".$_POST['email']."'") or die(mysql_error());
if (($result) && (mysql_num_rows($result) == 1) && ($row = mysql_fetch_array($result))) {
$message = new phpMailer();
$message->From = "webmaster@mydomain.com";
$message->FromName = "Some From Name";
$message->isSMTP();
$message->Host = "mail.mydomain.com";
$message->Username = "webmaster@mydomain.com";
$message->Password = "1234";
$message->Subject = "Account Information";
$message->AddAddress($row['email']);
$message->IsHTML(true);

include("notification.php");
$bodyText = $row['name']."
<br><br>
Thank you for your request for your password.
<br>
Your password is: <font color=\"red\"><b>".$row['password']."</b></font>
<br>
Have a great day,
<br><br>
The staff
<br><br>
";
$message->Body = generateHTML($bodyText);
if(!$message->send())
print "Problem with sending the message";
}

and this is the notification.php page it includes

<?php
$message->AddEmbeddedImage('images/notification_01.jpg', 'notification_01', 'images/notification_01.jpg ');
$message->AddEmbeddedImage('images/notification_02.jpg', 'notification_02', 'images/notification_02.jpg ');
$message->AddEmbeddedImage('images/notification_03.jpg', 'notification_03', 'images/notification_03.jpg ');
$message->AddEmbeddedImage('images/notification_04.jpg', 'notification_04', 'images/notification_04.jpg ');
$message->AddEmbeddedImage('images/notification_06.jpg', 'notification_06', 'images/notification_06.jpg ');
$message->AddEmbeddedImage('images/notification_07.jpg', 'notification_07', 'images/notification_07.jpg ');
$message->AddEmbeddedImage('images/notification_08.jpg', 'notification_08', 'images/notification_08.jpg ');
$message->AddEmbeddedImage('images/notification_09.jpg', 'notification_09', 'images/notification_09.jpg ');
$message->AddEmbeddedImage('images/notification_10.jpg', 'notification_10', 'images/notification_10.jpg ');
$message->AddEmbeddedImage('images/notification_11.jpg', 'notification_11', 'images/notification_11.jpg ');
$message->AddEmbeddedImage('images/notification_12.jpg', 'notification_12', 'images/notification_12.jpg ');
$message->AddEmbeddedImage('images/notification_13.jpg', 'notification_13', 'images/notification_13.jpg ');
$message->AddEmbeddedImage('images/notification_14.jpg', 'notification_14', 'images/notification_14.jpg ');
$message->AddEmbeddedImage('images/notification_15.jpg', 'notification_15', 'images/notification_15.jpg ');
$message->AddEmbeddedImage('images/notification_16.jpg', 'notification_16', 'images/notification_16.jpg ');
$message->AddEmbeddedImage('images/notification_17.jpg', 'notification_17', 'images/notification_17.jpg ');
$message->AddEmbeddedImage('images/spacer.gif', 'spacer', 'images/spacer.gif ');


function generateHTML($text) {
$email = "";
$email .= "
<table id=\"Table_01\" width=\"703\" height=\"575\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td colspan=\"7\">
<img src=\"cid:notification_01\" width=\"703\" height=\"136\" alt=\"\"></td>
</tr>
<tr>
<td>
<img src=\"cid:notification_02\" width=\"120\" height=\"82\" alt=\"\"></td>
<td colspan=\"2\">
<img src=\"cid:notification_03\" width=\"153\" height=\"82\" alt=\"\"></td>
<td>
<img src=\"cid:notification_04\" width=\"74\" height=\"82\" alt=\"\"></td>
<td colspan=\"3\" rowspan=\"3\" bgcolor=\"#FFFFFF\">
".$text."</td>
</tr>
<tr>
<td>
<img src=\"cid:notification_06\" width=\"120\" height=\"115\" alt=\"\"></td>
<td colspan=\"2\">
<img src=\"cid:notification_07\" width=\"153\" height=\"115\" alt=\"\"></td>
<td>
<img src=\"cid:notification_08\" width=\"74\" height=\"115\" alt=\"\"></td>
</tr>
<tr>
<td>
<img src=\"cid:notification_09\" width=\"120\" height=\"64\" alt=\"\"></td>
<td colspan=\"2\">
<img src=\"cid:notification_10\" width=\"153\" height=\"64\" alt=\"\"></td>
<td>
<img src=\"cid:notification_11\" width=\"74\" height=\"64\" alt=\"\"></td>
</tr>
<tr>
<td colspan=\"2\" rowspan=\"3\">
<img src=\"cid:notification_12\" width=\"241\" height=\"177\" alt=\"\"></td>
<td colspan=\"4\">
<img src=\"cid:notification_13\" width=\"294\" height=\"92\" alt=\"\"></td>
<td rowspan=\"3\">
<img src=\"cid:notification_14\" width=\"168\" height=\"177\" alt=\"\"></td>
</tr>
<tr>
<td colspan=\"3\">
<img src=\"cid:notification_15\" width=\"147\" height=\"44\" alt=\"\"></td>
<td rowspan=\"2\">
<img src=\"cid:notification_16\" width=\"147\" height=\"85\" alt=\"\"></td>
</tr>
<tr>
<td colspan=\"3\">
<img src=\"cid:notification_17\" width=\"147\" height=\"41\" alt=\"\"></td>
</tr>
<tr>
<td>
<img src=\"cid:spacer\" width=\"120\" height=\"1\" alt=\"\"></td>
<td>
<img src=\"cid:spacer\" width=\"121\" height=\"1\" alt=\"\"></td>
<td>
<img src=\"cid:spacer\" width=\"32\" height=\"1\" alt=\"\"></td>
<td>
<img src=\"cid:spacer\" width=\"74\" height=\"1\" alt=\"\"></td>
<td>
<img src=\"cid:spacer\" width=\"41\" height=\"1\" alt=\"\"></td>
<td>
<img src=\"cid:spacer\" width=\"147\" height=\"1\" alt=\"\"></td>
<td>
<img src=\"cid:spacer\" width=\"168\" height=\"1\" alt=\"\"></td>
</tr>
</table>";
return $email;
}


?>


any help would be appreciated,
thanks

Stephen Philbin
09-20-2005, 07:10 AM
OOP in PHP4 and PHP5 are quite different, you need to state which PHP you use whenever you ask about OOP in PHP. Looking at that code though, it looks like you're missing quite a bit of key information. I think you would probably find having a read of the OOP sections of the manual to be a great help.

Here's the manual section for OOP in PHP4:
http://www.zend.com/manual/language.oop.php

and here's the manual section for OOP in PHP5:
http://www.zend.com/manual/language.oop5.php

Good luck. ;)

Natcon67
09-20-2005, 09:39 AM
Stephen, thank you for replying to my post.
I am using PHP 4.3.9.
As it may be evident, I am using phpMailer from http://phpmailer.sourceforge.net/ and it was actually working without any problem.
Quite honestly, i dont know when or what changed to start giving me the error but I did have a working email notification from this code. Can you tell me what you think is missing so i can start to look it over?
I intentionally did not post the class.phpmailer.php code because it is enormous.

Once again, thanks for replying to the post.

Natcon67
09-20-2005, 10:23 AM
Also, if I comment out all of the

$message->AddEmbeddedImage('images/notification_01.jpg', 'notification_01', 'images/notification_01.jpg ');

lines, the script will run and send out an email, it just wont embed the images.

SpectreReturns
09-20-2005, 08:31 PM
Guess what. That means AddEmbeddedImage isn't a method of $message.

Stephen Philbin
09-21-2005, 02:25 AM
Well if everything was in the same file, I can't think why it might be doing that. The only thing I can think of that might be causing the problem is that the fact those method calls are in an include is what is causing the error.

At a guess, I'd say PHP is trying to parse the code and then include it afterwards. If that was the case, then the included file would have no reference to the $message object untill it is too late. Other than that, I'm not sure. Wrong capitolisation of the method name maybe?