Page 1 of 1

Call to a member function on a non-object

Posted: Tue Sep 25, 2007 7:35 am
by roscoe
OK when I //

Code: Select all

$swift->disconnect();
it works, if I leave this in I get the error.

Any ideas? :?

Posted: Tue Sep 25, 2007 8:04 am
by Zoxive
We are going to need to see more code.

What the error is saying is that $swift isn't an object.
Call to a member function on a non-object

Posted: Tue Sep 25, 2007 8:42 am
by Chris Corbyn
Yep, more code please :)

Posted: Tue Sep 25, 2007 10:26 am
by roscoe
d11wtq wrote:Yep, more code please :)
OK here we go

Code: Select all

set_time_limit(0);
ignore_user_abort();
foreach($_POST AS $key => $value) {
    ${$key} = $value;
}
foreach($_GET AS $key => $value) {
    ${$key} = $value;
}

global $stopped, $entrydate;

$table= "sendoutlist";
$stopped = "n";
$entrydate = date("Y-m-d");

require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$sql2 = "SELECT * FROM sendoutlist WHERE entrydate <  '$entrydate' AND done = 'NULL' AND stopped = '$stopped' or entrydate =  '$entrydate' AND done = 'NULL' AND stopped = '$stopped'";


$resultsx = mysql_query($sql2) or die("An error ocurred :".mysql_error());

        while ($row = mysql_fetch_array($resultsx)) {
$myID = $row['jobid'];
$title = $row['mailSubject'];
$listname = $row['listname'];
$lastemail = $row['lastemail'];
//echo $myID;
if ($lastemail != "")
{
//check listcounter
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$sql3 = "SELECT * FROM listcounter WHERE listname = '$listname' AND jobid = '$myID'";
//echo $sql3;
$results3 = mysql_query($sql3) or die("An error ocurred :".mysql_error());
        while ($row = mysql_fetch_array($results3)) {
$themail = $row['lastemail'];
$howmany = $row['howmany'];
// count of emails should not exceed 4200  per 24 hours

}


require_once ("/home/arsenal/public_html/control/hideme/connect.inc");


$mailBody = "";
$table= "walter";
    // For each vac line...
$sql4 = "SELECT * FROM $table WHERE jobid = '$myID'";

$results4 = mysql_query($sql4) or die("An error ocurred :".mysql_error());
        while ($row = mysql_fetch_array($results4)) {



$ID = $row["jobid"];
$contact = $row["user"];
$emailadd = $row["useremail"];
$mycat = $row["cat"];
$title = $row["title"];
$salary = $row["salary"];
$location = $row["location"];
$description = $row["skills"];
$benefits = $row["benefits"];


$description=str_replace("#","/n",$description);











$mailBody =$mailBody."\n\nHere is the latest  vacancy, ID number {$ID} \n\n Job Title: {$title} \n\n Salary: {$salary} Benefits{$benefits} Location {$location}\n\n{$description} \n\n If you would like to apply for this position please email {$emailadd} or call {$contact} at \n\Ltd\n330 7QT\nTel: +44 (0)1898\nFax: +44 (0)\n\nIf you wish to unsubscribe to $mycat mail list, please unsubscribe at http://www.y.com";






}

            // Set up reply address for mailing list
    $mailFrom = "u<jobs@y.com>";

    // Ensure that subject and body of email have
    // automatically inserted escape slashes removed




$name = " Employment";
$email = "jobs@g.com";
$title = $_POST["mailSubject"];
$sender = $email;


    // Attempt to read subscriber file
$x=0;
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$table= "jobmailtest";
$sql5 = "SELECT * FROM $table WHERE  mylist = '$listname'";
 $resultsb = mysql_query($sql5) or die("An error ocurred :".mysql_error());
        while ($row = mysql_fetch_array($resultsb)) {
              $theid = $row["id"];
              $sendout = $row["mymail"];
      
              $theirname = $row["myname"];
           
              $x= $x +1;

require_once "mailoutattach/mylib/Swift.php";

//change this to smtp
require_once "mailoutattach/mylib/Swift/Connection/SMTP.php";
//echo "$listname <br>$sendout, $theirname<br>";

require_once "mailoutattach/mylib/Swift/Plugin/Throttler.php";

//$swift =& new Swift(new Swift_Connection_SMTP("smtp.host.tld"));
$mailBody2 = "Dear $theirname,\n\n".$mailBody;

$body=stripslashes($mailBody2);


//Enable disk caching if we can
if (is_writable("/tmp"))
{
    Swift_CacheFactory::setClassName("Swift_Cache_Disk");
    Swift_Cache_Disk::setSavePath("/tmp");
}
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
$message =& new Swift_Message("Latest Vacancy" . $title);
$message->attach(new Swift_Message_Part($body));
$throttler =& new Swift_Plugin_Throttler();
$throttler->setBytesPerMinute(20000000); //Roughly 20MB

$swift->attachPlugin($throttler, "throttler");

//or maybe you want to set the number of messages per minute?

$throttler->setEmailsPerMinute(3); //Max of 1 email every 2 seconds



//Try sending the email
$sent = $swift->send($message, $sendout, $sender);

}


if ($sent)
{

$today =date("Ymd");
if ($x == $howmany){
echo "$x = $howmany";
	$lastadd = $sendout;
	$mymessage = "done sending $ID to all in the list -lat address is  $lastadd   Success!";
	//$message->attach(new Swift_Message_Part($body));
    $mailSubject = "notification";
    $mailFrom = "jobs@y.com";
    $mymail = "perry@y.com";
    mail($mymail, $mailSubject, $mymessage, $mailFrom);

$stopped = "n";
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
 $sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped', lastemail = '$lastemail'  WHERE jobid ='$myID'";
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());


require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$sqlL = "UPDATE listcounter SET datedone = '$today', lastemail = '$lastemail'  WHERE jobid ='$myID'";

    $myresult2L = mysql_query($sqlL) or die("An error ocurred :".mysql_error());

                 }

if ($x > $howmany){

	$lastadd = $sendout;
   $mymessage = "done sending $ID to $lastadd Success!\n\nSent out $x";


$mailSubject = "notification";
    $mailFrom = "jobs@y.com";
    $mymail = "perry@y.com";
    mail($mymail, $mailSubject, $mymessage, $mailFrom);
	require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$stopped = "n";
 $sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastemail'  WHERE jobid='$myID'";
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$sqlL = "UPDATE listcounter SET datedone = '$today', lastemail = '$lastemail'  WHERE jobid ='$myID'";
$myresult2L = mysql_query($sqlL) or die("An error ocurred :".mysql_error());

                 }
if ($x < $howmany){

$lastadd = $sendout;

require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$table= "jobmailtest";
$z= 0;
    // For each vac line....
$sql2 = "SELECT * FROM $table WHERE mylist = '$listname'";

$results = mysql_query($sql2) or die("An error ocurred :".mysql_error());
        while ($row = mysql_fetch_array($results)) {
        $lastmail = $row['mymail'];
         $z = $z + 1;
}

If ($z==$x){

$mymessage = "done sending $ID to $lastadd Success!\n\nSent out $x";

    $mailSubject = "notification";
    $mailFrom = "jobs@y.com";
    $mymail = "perry@y.com";
    mail($mymail, $mailSubject, $mymessage, $mailFrom);

require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$stopped = "n";
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastemail'  WHERE jobid='$myID'";

    $myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());
}else{

$mymessage = "done sending $ID Failed to complete, last email to $lastadd \n\nSent out $z";

    $mailSubject = "notification";
    $mailFrom = "jobs@y.com";
    $mymail = "ros@y.com";
    mail($mymail, $mailSubject, $mymessage, $mailFrom);
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$stopped = "y";
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastemail'  WHERE jobid='$myID'";

$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());

             }}
else{     $mymessage = "sending_failed $ID, Stopped on $sendout";

    $mailSubject = "notification";
    $mailFrom = "jobs@y.com";
    $mymail = "ros@y.com";
    mail($mymail, $mailSubject, $mymessage, $mailFrom);


// store last email out
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$stopped = "y";
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastemail'  WHERE jobid='$myID'";
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());

//$swift->log->dump();

}}}   //end of while

//echo"endit";
 $swift->disconnect();

Posted: Tue Sep 25, 2007 5:39 pm
by Chris Corbyn
8O Your code is incredibly difficult to follow and perhaps it's just the incorrect indentation that leads me to see this but there seem to be far more closing } braces than opening ones.

Is the call to "new Swift()" inside some larger if condition which may not be satisfied?

What does this show? (Just above $swift->disconnect())

Code: Select all

var_dump($swift);

Posted: Wed Sep 26, 2007 3:29 am
by roscoe
Sorry, I learnt to code by myself so I had no one to teach me the correct indentation.

As to the brackets, they all do match (I have checked them all)

The program does the following:

Picks up if there is a mailout to do.
Checks how many are to go and the last address to send to
picks up the content of the email
fills in all the to and from stuff
picks up the first address to send to
picks up the swift here, connects smtp and throttles back speed of dispatch
collects the next email address till the job is done.

either successful or not and writes away result of mailout

goes back to check there are no more jobs to do

finally closes swift connection

All data IS present and emails dispatch without

Code: Select all

$swift->disconnect();
when I add the instruction it bombs :roll:

Posted: Wed Sep 26, 2007 3:51 am
by chuckl
Every time I've ever used a disconnect() I got the same error.

I just assumed that the connection had already been disconnected, and used the easiest fix - leave it out.

Posted: Wed Sep 26, 2007 6:32 pm
by Chris Corbyn
Please can you post the full error message? :) I'm not too sure which bit of Swift to be looking at without the error.

Posted: Fri Sep 28, 2007 8:47 am
by roscoe
d11wtq wrote:Please can you post the full error message? :) I'm not too sure which bit of Swift to be looking at without the error.
As per subject Call to a member function on a non-object

Posted: Fri Sep 28, 2007 9:20 am
by John Cartwright
roscoe wrote:
d11wtq wrote:Please can you post the full error message? :) I'm not too sure which bit of Swift to be looking at without the error.
As per subject Call to a member function on a non-object
As per d11's request, the full error message. You have only included a small portion of the error.

Posted: Fri Sep 28, 2007 9:39 am
by roscoe
Jcart wrote:
roscoe wrote:
d11wtq wrote:Please can you post the full error message? :) I'm not too sure which bit of Swift to be looking at without the error.
As per subject Call to a member function on a non-object
As per d11's request, the full error message. You have only included a small portion of the error.
That IS all there was :?

Posted: Fri Sep 28, 2007 9:48 am
by John Cartwright
roscoe wrote:
Jcart wrote:
roscoe wrote: As per subject Call to a member function on a non-object
As per d11's request, the full error message. You have only included a small portion of the error.
That IS all there was :?
I highly doubt that.. you should be seeing something like
Fatal error: Call to a member function bar() on a non-object in H:\wamp\www\Index.php on line 3