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]
This is my first time using SwiftMailer.
I am sending my emails through SMTP, and my script is saying that it's sending the message fine (it gets to if($sent)) but it's not (I actually changed the password to an incorrect password, and it still said it sent it fine)
Here is the relevant code:
require_once "swift/lib/Swift.php";
require_once "swift/lib/Swift/Connection/SMTP.php";
require_once "swift/lib/Swift/Authenticator/LOGIN.php";
//Create a Swift instance
$smtp =& new Swift_Connection_SMTP("mail.phazm.com", 25);
$smtp->setUsername("myuser");
$smtp->setPassword("mypass");
$swift =& new Swift($smtp);
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
//Create the message to send
$message =& new Swift_Message("New Message");
$message->attach(new Swift_Message_Part($body));
//Try sending the email
$sent = $swift->send($message, "nospam@phazm.com", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: ./contact.php?status=sent");
exit();
}
else
{
header("Location: ./contact.php?error=sending_failed");
exit();
}
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]
$swift =& new Swift($connection);
$swift->log->enable();
$swift->send( ... ); //Pseudo, send emails in the normal way
echo "<pre>", $swift->log->dump();
//Thinking out loud... it would be great if the log was dumped with the error stack trace when logging is enabled I'll add this to 3.3.
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]
Catchable fatal error: Argument 1 passed to Swift::__construct() must implement interface Swift_Connection, null given, called in /home/phazm/public_html/phazm/processform.php on line 52 and defined in /home/phazm/public_html/phazm/swift/lib/Swift.php on line 85
It's possible I added this to the wrong spot, however...
//Create the message to send
$message =& new Swift_Message("PZMAIL -- New Message");
$message->attach(new Swift_Message_Part($body));
$swift =& new Swift($connection);
$swift->log->enable();
//Try sending the email
$sent = $swift->send($message, "nospam@phazm.com", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
echo "<pre>", $swift->log->dump();
if ($sent)
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]
Catchable fatal error: Argument 1 passed to Swift::__construct() must implement interface Swift_Connection, null given, called in /home/phazm/public_html/phazm/processform.php on line 53 and defined in /home/phazm/public_html/phazm/swift/lib/Swift.php on line 85
<?
if (empty($_POST["fname"]) || empty($_POST["lname"])
|| empty($_POST["email"]) || empty($_POST["message"]))
{
header("Location: ./contact.php?error=blank");
exit();
}
if ($passed != "yes")
{
header("Location: ./contact.php?error=nopass");
exit();
}
$fname = $_POST["fname"];
$email = $_POST["lname"];
$email = $_POST["email"];
$message = $_POST["message"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $email))
{
header("Location: ./contact.php?error=invalid_email");
exit();
}
require_once "swift/lib/Swift.php";
require_once "swift/lib/Swift/Connection/SMTP.php";
require_once "swift/lib/Swift/Authenticator/LOGIN.php";
/*Enable disk caching if we can
if (is_writable("swift/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("swift/tmp");
}
*/
$name = "$fname $lname";
//Create a Swift instance
$smtp =& new Swift_Connection_SMTP("mail.phazm.com", 25);
$smtp->setUsername("myuser");
$smtp->setPassword("mypass");
$swift =& new Swift($smtp);
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
try {
//Create the message to send
$message =& new Swift_Message("PZMAIL -- New Message");
$message->attach(new Swift_Message_Part($body));
$swift =& new Swift($connection);
$swift->log->enable();
//Try sending the email
$sent = $swift->send($message, "nospam@phazm.com", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
} catch (Exception $e) {
echo "Error caught<br />";
}
echo "<pre>", $swift->log->dump();
if ($sent)
{
header("Location: ./contact.php?status=sent");
exit();
}
else
{
header("Location: ./contact.php?error=sending_failed");
exit();
}
?>
<?php
if (empty($_POST["fname"]) || empty($_POST["lname"])
|| empty($_POST["email"]) || empty($_POST["message"]))
{
header("Location: ./contact.php?error=blank");
exit();
}
if ($passed != "yes")
{
header("Location: ./contact.php?error=nopass");
exit();
}
$fname = $_POST["fname"];
$email = $_POST["lname"];
$email = $_POST["email"];
$message = $_POST["message"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $email))
{
header("Location: ./contact.php?error=invalid_email");
exit();
}
require_once "swift/lib/Swift.php";
require_once "swift/lib/Swift/Connection/SMTP.php";
require_once "swift/lib/Swift/Authenticator/LOGIN.php";
/*Enable disk caching if we can
if (is_writable("swift/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("swift/tmp");
}
*/
$name = "$fname $lname";
//Create a Swift instance
$smtp =& new Swift_Connection_SMTP("mail.phazm.com", 25);
$smtp->setUsername("myuser");
$smtp->setPassword("mypass");
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
try {
//Create the message to send
$message =& new Swift_Message("PZMAIL -- New Message");
$message->attach(new Swift_Message_Part($body));
$swift =& new Swift($smtp);
$swift->log->enable();
//Try sending the email
$sent = $swift->send($message, "nospam@phazm.com", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
} catch (Exception $e) {
echo "Error caught<br />";
}
echo "<pre>", $swift->log->dump();
if ($sent)
{
header("Location: ./contact.php?status=sent");
exit();
}
else
{
header("Location: ./contact.php?error=sending_failed");
exit();
}
?>
++ Enabling logging
>> MAIL FROM:
<< 250 OK
>> RCPT TO:
<< 250 Accepted
>> DATA
<< 354 Enter message, ending with "." on a line by itself
>>
>>
.
<< 250 OK id=1I55bZ-0005Op-Hn
++ Message sent to 1/1 recipients
>> QUIT
<< 221 gator104php5sql5.hostgator.com closing connection
Warning: Cannot modify header information - headers already sent by (output started at /home/phazm/public_html/phazm/processform.php:63) in /home/phazm/public_html/phazm/processform.php on line 67