Page 1 of 1
another swiftmailer problem
Posted: Wed Jun 27, 2007 11:08 pm
by nomb
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
Posted: Wed Jun 27, 2007 11:17 pm
by John Cartwright
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);
Posted: Wed Jun 27, 2007 11:20 pm
by nomb
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";
?>
Posted: Wed Jun 27, 2007 11:23 pm
by John Cartwright
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

Posted: Wed Jun 27, 2007 11:27 pm
by nomb
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
Posted: Wed Jun 27, 2007 11:29 pm
by John Cartwright
nomb wrote:ok I copied exactly what you had:
No you didn't

Posted: Wed Jun 27, 2007 11:31 pm
by nomb
oh lol ur right. I apologize.
Posted: Thu Jun 28, 2007 12:05 am
by feyd
This is a duplicate thread. Please don't do this again in the future.