Page 1 of 1

Sending two attachments with swift mailer

Posted: Fri Sep 26, 2008 11:34 pm
by hhstables
I'm new to swift mailer:
This is my code:
<?php
//Copy into global variables
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$title = $_POST["comment_title"];
$body = $_POST["comment_body"];

//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if ($_FILES["attachment"]["error"] > 0)
{
echo "Return Code: " . $_FILES["attachment"]["error"] . "<br />";
}
else
if (is_uploaded_file($_FILES['attachment']['tmp_name']))
{
echo "Upload: " . $_FILES["attachment"]["name"] . "<br />";
echo "Type: " . $_FILES["attachment"]["type"] . "<br />";
echo "Size: " . ($_FILES["attachment"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["attachment"]["tmp_name"] . "<br />";
}
else
{
echo "File Not Uploaded: ";
echo "filename '". $_FILES['attachment']['tmp_name'] . "'.";
}

$file_path1 = false;
$file_name1 = false;
$file_type1 = false;

if ($_FILES["attachment1"]["error"] > 0)
{
echo "Return Code: " . $_FILES["attachment1"]["error"] . "<br />";
}
else
if (is_uploaded_file($_FILES['attachment1']['tmp_name']))
{
echo "Upload: " . $_FILES["attachment1"]["name"] . "<br />";
echo "Type: " . $_FILES["attachment1"]["type"] . "<br />";
echo "Size: " . ($_FILES["attachment1"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["attachment1"]["tmp_name"] . "<br />";
}
else
{
echo "File Not Uploaded: ";
echo "filename '". $_FILES['attachment1']['tmp_name'] . "'.";
}
//Everything looks ok, we can start Swift

require_once "swift/lib/Swift.php";
require_once "swift/lib/Swift/Connection/SMTP.php";

//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}

//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("mail.xxxxxxx.com"));

//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 comment: " . $title);
$message->attach(new Swift_Message_Part($body));

//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
if ($file_path1 && $file_name1 && $file_type1)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path1), $file_name1, $file_type1));
}
//Try sending the email
$sent = $swift->send($message, "xxxxx@xxxx.com", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();

if ($sent)
{
echo "<p>The email was sent.</p>";
}
else
{
echo "<p>There was an error sending the mail.</p>";
exit();
}


?>
this is my error:
File Not Uploaded: filename ''.File Not Uploaded: filename ''.
Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'The SMTP connection failed to start [mail.hhstables.com:25]: fsockopen returned Error Number 111 and Error String 'Connection refused'' in /home/hhstable/public_html/test/swift/lib/Swift/Connection/SMTP.php:309 Stack trace: #0 /home/hhstable/public_html/test/swift/lib/Swift.php(216): Swift_Connection_SMTP->start() #1 /home/hhstable/public_html/test/swift/lib/Swift.php(101): Swift->connect() #2 /home/hhstable/public_html/test/mail.php(69): Swift->__construct(Object(Swift_Connection_SMTP)) #3 {main} thrown in /home/hhstable/public_html/test/swift/lib/Swift/Connection/SMTP.php on line 309