PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nomb
Forum Newbie
Posts: 19 Joined: Thu May 24, 2007 3:24 pm
Post
by nomb » Wed Jun 27, 2007 11:08 pm
sorry this is probably something simple as well: Fatal error: Call to undefined method Swift::setUsername() in /home/phantomcyph/public_html/contact/mailer.php on line 9
and the code:
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Authenticator/LOGIN.php";
$conn =& new Swift(new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
$conn->setUsername("xxxxxxxxxxxxx");
$conn->setpassword("xxxxxxxxxx");
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift =& new Swift($conn);
//Create the message
$name = $_POST["Name"];
$email = $_POST["Email"];
$response = $_POST["Need response?"];
$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, "phantomcyph@gmail.com", "phantomcyph@gmail.com")) echo "Sent";
else echo "Failed";
?>
Thanks again,
nomb
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jun 27, 2007 11:17 pm
As per the
documentation , you are supposed to be setting the username and password to the SMTP object, not the swift object
Code: Select all
$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$conn->setUsername("xxxxxxxxxxxxx");
$conn->setpassword("xxxxxxxxxx");
$conn =& new Swift($smtp);
nomb
Forum Newbie
Posts: 19 Joined: Thu May 24, 2007 3:24 pm
Post
by nomb » Wed Jun 27, 2007 11:20 pm
I gave that a try.
Error:
Fatal error: Call to a member function setUsername() on a non-object in /home/phantomcyph/public_html/contact/mailer.php on line 9
Code:
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Authenticator/LOGIN.php";
$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$conn->setUsername("phantomcyph");
$conn->setpassword("jusufu08");
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$conn =& new Swift($smtp);
//Create the message
$name = $_POST["Name"];
$email = $_POST["Email"];
$response = $_POST["Need response?"];
$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, "phantomcyph@gmail.com", "phantomcyph@gmail.com")) echo "Sent";
else echo "Failed";
?>
Last edited by
nomb on Wed Jun 27, 2007 11:23 pm, edited 1 time in total.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jun 27, 2007 11:23 pm
Jcart wrote: As per the
documentation , you are supposed to be setting the username and password to the SMTP object, not the swift object
Code: Select all
$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$conn->setUsername("xxxxxxxxxxxxx");
$conn->setpassword("xxxxxxxxxx");
$conn =& new Swift($smtp);
Should be
Code: Select all
$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername("xxxxxxxxxxxxx");
$smtp->setpassword("xxxxxxxxxx");
$swift =& new Swift($smtp);
Sorry, was using wrong variable name in my snipplet, however from your last thread you should be aware of this problem
nomb
Forum Newbie
Posts: 19 Joined: Thu May 24, 2007 3:24 pm
Post
by nomb » Wed Jun 27, 2007 11:27 pm
ok I copied exactly what you had:
error: Fatal error: Call to a member function setUsername() on a non-object in /home/phantomcyph/public_html/contact/mailer.php on line 9
and code:
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Authenticator/LOGIN.php";
$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$conn->setUsername("xxxxxxxxxx");
$conn->setpassword("xxxxxxxx");
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN()); <-- I did try without this line as well
$swift =& new Swift($smtp);
//Create the message
$name = $_POST["Name"];
$email = $_POST["Email"];
$response = $_POST["Need response?"];
$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, "phantomcyph@gmail.com", "phantomcyph@gmail.com")) echo "Sent";
else echo "Failed";
?>
Jcart | Removed credentials
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jun 27, 2007 11:29 pm
nomb wrote: ok I copied exactly what you had:
No you didn't
nomb
Forum Newbie
Posts: 19 Joined: Thu May 24, 2007 3:24 pm
Post
by nomb » Wed Jun 27, 2007 11:31 pm
oh lol ur right. I apologize.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 28, 2007 12:05 am
This is a duplicate thread. Please don't do this again in the future.