Yii Framework Forum: Yii Swiftmailer - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Swiftmailer Rate Topic: -----

#1 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 118
  • Joined: 24-January 12

Posted 11 October 2012 - 04:17 AM

Can someone help me out here, been trying to do a fiel upload and attachment. I have this on my SiteController

{if(isset($_POST["submit"])){
if(!isset($_POST["first_name"]) 
	|| !isset($_POST["file"]))
 { 
 echo "MOO";
} else{
 $first_name = $_POST['first_name'];
$fileupload = $_POST['file'];

}
 $message = new YiiMailMessage;
 $message->setBody($first_name);
 $message->subject = 'My Subject';
 $message->addTo('my@domain.com');
 $message->from = Yii::app()->params['adminEmail'];



$message->attach(
Swift_Attachment::fromPath($_FILES['file']['tmp_name'])->setFilename($_FILES['file']['name'])
);


//$message->attach(Swift_Attachment::fromPath($fileupload)); -- This works
 Yii::app()->mail->send($message);
}

?>


My index
<form name="contactform" method="post">
 
  <label for="first_name">First Name *</label>
 
 <input type="submit" value="submit" name="submit" > 
 
  <input  type="text" name="first_name" maxlength="50" size="30">
  Attachment: <input type="file" name="file"> 

 </td>


I get Undefined index: file..... Doesn't $_FILES take everything from post action? Also the action is going to the Controller as the form variables are taken.

Thanks
0

#2 User is offline   oxigen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 05-February 09

Posted 12 October 2012 - 01:35 AM

replace
<form name="contactform" method="post">


by

<form name="contactform" method="post" enctype="multipart/form-data">

1

#3 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 12 October 2012 - 01:43 AM

/* Moved from General Discussion to Extensions ... */
"Less noise - more signal"
0

#4 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 118
  • Joined: 24-January 12

Posted 13 October 2012 - 03:44 AM

View Postoxigen, on 12 October 2012 - 01:35 AM, said:

replace
<form name="contactform" method="post">


by

<form name="contactform" method="post" enctype="multipart/form-data">



Yh that's done it, thanks mate. So simple yet I would have never figured it out.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users