[SOLVED] Uncaught Error of type [swift_fileexception] with

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
kigoobe
Forum Commoner
Posts: 38
Joined: Mon Jul 10, 2006 3:26 am

[SOLVED] Uncaught Error of type [swift_fileexception] with

Post by kigoobe »

Hi

I have just upgraded from 2.1.17 to 3.2.4 and was trying to test attachments ...

Here is what I got.

Code: Select all

Fatal error: 
Uncaught Error of type [swift_fileexception] with message [No such file 'orcut.jpg']
@0 swift_file::swift_file() in /home/usr/public_html/post.php on line 81
@1 swift_file::setpath() in /home/usr/public_html/Swift-3.2.4-php4/Swift/File.php on line 52

in /home/usr/public_html/Swift-3.2.4-php4/Swift/Errors.php on line 99
Can anyone help ?
Thanks. :)

The full code, by the way ...

Code: Select all

$objetcordo=stripslashes($_POST['objet-cordo']);
$themessage=htmlentities($_POST['themessage'],ENT_QUOTES);
$sender = $prenom.' '.$nom.' <'.$email.'>';
$recipients = $_POST['moncor'];


if (is_uploaded_file($_FILES['dossier']['tmp_name'])) {  ############ if a file is submitted
set_time_limit(8000);
$allowed_types = array(".pdf", ".doc", ".txt",  ".xls", ".ppt", ".jpg", ".jpeg", ".pjpeg",  ".png", ".x-png"); 
$uploadfile=$_FILES['dossier']['tmp_name'];
$uploadname=$_FILES['dossier']['name'];
$uploadtype=$_FILES['dossier']['type'];

$pos = strrpos($uploadname, '.');
$extension = substr($uploadname, $pos);
							
if(!in_array($extension, $allowed_types)) {
 ########### Error messages ...
}
								
if ($extension == ".pdf") { $mymime = "application/pdf"; } else
if ($extension == ".doc") { $mymime = "application/msword"; } else
if ($extension == ".txt") { $mymime = "text/plain"; } else
if ($extension == ".xls") { $mymime = "application/excel"; } else
if ($extension == ".ppt") { $mymime = "application/mspowerpoint"; } else
if ($extension == ".jpg") { $mymime = "image/jpeg"; } else
if ($extension == ".jpeg") { $mymime = "image/jpeg"; } else
if ($extension == ".pjpeg") { $mymime = "image/pjpeg"; } else
if ($extension == ".png") { $mymime = "image/png"; } else
if ($extension == ".x-png") { $mymime = "image/png"; }
}
							
require_once "Swift-3.2.4-php4/Swift.php"; ###  lib/ renamed as Swift-3.2.4-php4/
require_once "Swift-3.2.4-php4/Swift/Connection/NativeMail.php";

$swift =& new Swift(new Swift_Connection_NativeMail());

$message =& new Swift_Message($objetcordo);
$message->attach(new Swift_Message_Part($themessage, "text/html"));
$message->attach(new Swift_Message_Attachment(new Swift_File($uploadname), $uploadname, $mymime));

$recipientz =& new Swift_RecipientList();
$recipientz->addTo($email); 
	foreach ($recipients as $recipient) {
		if ($recipient != '') {
		$recipientz->addBcc($recipient);
		}
	}

if ($swift->send($message, $recipients,  new Swift_Address($email, $prenom.' '.$nom) )) {

	?>
	<h5 align="center" style="color:#006DC6;">Mail envoyé</h5>
	Bonjour <?=$prenom?> <?=$nom?><br /><br />
	Votre mail &agrave; bien &eacute;t&eacute; envoy&eacute;e &agrave;<br />
	Veuillez noter que une copie de ce message vous sera automatiquement envoy&eacute;e<br />
	<br />
	<?php
	} else {
	print '<div align="center" style="color:#FF0000;font-size:21px;">Erreur ... veuillez essayer ult&eacute;rieurement</div>';
	}
   	$swift->disconnect();
	
	}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You should be using:

Code: Select all

$message->attach(new Swift_Message_Attachment(new Swift_File($uploadfile), $uploadname, $mymime));
$uploadname is simply the filename -- not the path to it.
kigoobe
Forum Commoner
Posts: 38
Joined: Mon Jul 10, 2006 3:26 am

Post by kigoobe »

Hi Chris

Thanks a lot. I'm getting this now -

Code: Select all

Fatal error: Call to a member function on a non-object in /home/usr/public_html/post.php on line XXX
What do you think?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

kigoobe wrote:Hi Chris

Thanks a lot. I'm getting this now -

Code: Select all

Notice: The recipients parameter must either be a valid string email address, an instance of Swift_RecipientList or an instance of Swift_Address. in /home/usr/public_html/Swift-3.2.4-php4/Swift.php on line XXX
What do you think?
I think that the recipients parameter must either be a valid string email address, an instance of Swift_RecipientList or an instance of Swift_Address. :wink:

Why do you have a $recipientz variables and a $recipients variable?
Maybe you should try using $recipientz in the send function instead of $recipients.
Last edited by superdezign on Tue May 29, 2007 9:57 am, edited 2 times in total.
kigoobe
Forum Commoner
Posts: 38
Joined: Mon Jul 10, 2006 3:26 am

Post by kigoobe »

yeah right, this was this !!!!!!!!!!!!!!!!!!

Thanks, solved !!! :wink:
Post Reply