attempting to use swiftmailer

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
nomb
Forum Newbie
Posts: 19
Joined: Thu May 24, 2007 3:24 pm

attempting to use swiftmailer

Post by nomb »

I'm attempting to use swiftmailer and get this error: Fatal error: Call to a member function setUsername() on a non-object in /var/www/scripts/test.php on line 9

Here is my code:

Code: Select all

<?php
 
//Load in the files we'll need
require_once "swift/lib/Swift.php";
require_once "swift/lib/Swift/Connection/SMTP.php";
require_once "swift/lib/Swift/Authenticator/LOGIN.php";
 
$conn =& new Swift_Connection_SMTP("smtp.xxxxxxxx.net");
$smtp->setUsername("xxxxxx");
$smtp->setpassword("xxxxxx");
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
 
$swift =& new Swift($conn);
 
//Create the message

$name = $_POST["name"];
$email = $_POST["email"];

$body .= "Name: $name\n";
$body .= "Email: $email\n";
$body .= "\n";
$body .= $_POST["message"]; 

$message =& new Swift_Message("A new message from your website.", $body);
 
//Now check if Swift actually sends it
if ($swift->send($message, "webmaster@nombyte.com", "nomb85@comcast.net")) echo "Sent";
else echo "Failed";

?>
Thank you for any help.

nomb
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$conn vs $smtp... ;)
nomb
Forum Newbie
Posts: 19
Joined: Thu May 24, 2007 3:24 pm

Post by nomb »

Bah, [s]ur[/s] you're right. I must have been stairing at it too long... :D

I must say out of all the forums I've been a part of, you are by far the most helpful and quickest person ever.

Thanks for everything.

nomb
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

nomb wrote:I must say out of all the forums I've been a part of, you are by far the most helpful and quickest person ever.
Thanks. We try. :)
Post Reply