Page 1 of 1

Fatal error: Call to undefined method Swift::setUsername()

Posted: Sat Dec 29, 2007 4:04 pm
by howedav
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,
Newbie to Swift and to PHP5. Done lots of non-OOP php4 and been waiting for an excuse to move up.
Anyhow, I am getting Subject errror with the very first test mail I have tried sending.
Tried my host server, then my gmail account using the code right out of your docs and keep getting undefined method messages.
I suspect I have something misconfigured but I have not searched the lib code for the functions.

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
 
//Start Swift
$smtp = new Swift(new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
 
$smtp->setUsername("me");
$smtp->setPassword("dontUwish"); 
//Create the message
$message = new Swift_Message("My subject", "My body lies over the ocean");
 
//Now check if Swift actually sends it
if($smtp->send($message, "folkart@berkshire.net", "howedav@gmail.com"))echo "Sent";
else echo "Failed";
?>
I run this code and I get the error:
Fatal error: Call to undefined method Swift::setUsername() in /home/sallyand/www/www/Swift-php5/testSwift.php on line 12


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

PHP Version

Posted: Mon Dec 31, 2007 2:43 pm
by howedav
I have been searching the web trying to figure this out and seem to run in to lots of version issues.
For the record, the code failing above is running on PHP Version 5.2.5 server.
I also put a little echo in SMTP.php to make sure I am including it, since that is where the setUsername function lives. I do get the text echo onto the screen, so I know I am including the file with the function. But the error says method. What method???

Posted: Tue Jan 01, 2008 1:05 pm
by John Cartwright
The Swift object does not contain the setUsername() and setPassword() methods, these are found within the connection class.

Code: Select all

error_reporting(E_ALL); ini_set('display_errors', true);
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
 
$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername("me");
$smtp->setPassword("dontUwish"); 

$swift = new Swift($smtp);
$message = new Swift_Message("My subject", "My body lies over the ocean");
 
//Now check if Swift actually sends it
if($swift->send($message, "folkart@berkshire.net", "howedav@gmail.com"))echo "Sent";
else echo "Failed";