Page 1 of 1

Getting a Fatal Error using swift

Posted: Thu Apr 23, 2009 12:10 am
by geddi
Hi,

I am trying to use the swift 4 class for sending
email.

Here is my script:

Code: Select all

<?php 
/* 
*    news_send.php
*/
 
Swift_Message::newInstance();
 
// set the sender
$message->setFrom(array('Editor@expert-world.com' => 'James Burke'));
 
// set the recipient
$message->setTo(array('$email' => '$contact'));
 
// set the subject
$message->setSubject('$subject');
 
// set the html body
$message->setBody('$message', 'text/html');
 
// set the text body
$message->addPart('$message_text', 'text/plain');
 
//Send the message
if (!$mailer->send($message, $failures)) {
    echo "<div class=\"ctrl_lister\">
        <span class= \"lk\">$Rctr ) Failed to Send Edn 1 to :$user_id, at $failures</span>
        </div>";
        } // end if
else {
   // update database
     $sql = "UPDATE clients SET eml = eml+1 WHERE user_id = '$user_id'";
     mysql_query($sql) or die("could not execute adverts update query". mysql_error()); 
 
      echo "<div class=\"ctrl_lister\">
    <span class= \"lk\">$Rctr ) Sent Edn 1 to :$user_id, Type: $type, Contact: $contact, Joined:$join_dt</span>
    </div>";
    } // end else
 
$Rctr = $Rctr +1;           
/*
*  end of news_send.php
*/ 
?>
I get this error:
Fatal error: Call to a member function setFrom() on a non-object in /home/guru54gt5/public_html/im/news_send.php on line 9
Line line is: $message->setFrom(array('Editor@expert-world.com' => 'James Burke'));

Please help :)

Re: Getting a Fatal Error using swift

Posted: Thu Apr 23, 2009 12:38 am
by Chris Corbyn
You've forgotten to assign the return value of Swift_Message::newInstance() to $message.