php - Sending an uploaded file as attachment but not saving to server -


this might noob-ish question, new file uploading , mail sending. please bare me...

i have contact form on website allows user send files attachments email. reasoning that, not need or want every image uploaded website server, when using form input file gets uploaded anyways.

it makes sense form uploads file function know if inevitable or if there way still send images attachments not have uploaded server.

regards

pulled answer https://stackoverflow.com/a/23849972/ (and having spent time find them solution).

sidenote: upvoted answer pulled from, know.

"i assigned $_files['attachment']['tmp_name'] temporary variable , worked! dont know why solved me. here's code"

// swiftmail commands ==================================== require_once('./swiftmailer/lib/swift_required.php');  $transport = swift_smtptransport::newinstance('smtp.host.com', 587) ->setusername('email@host.com') ->setpassword('pass');  $mailer = swift_mailer::newinstance($transport);  $message = swift_message::newinstance() ->setsubject($subject_temp)  ->setfrom(array($from_email => $full_name))  ->setto(array('email@host.com' => 'jack'))  ->setbody($message_temp)  ->attach(swift_attachment::frompath($file_temp_name)  ->setfilename($name_of_file));  $result = $mailer->send($message);  // swiftmail commands ==================================== 

where $file_temp_name = $_files['attachment']['tmp_name']; , $name_of_file = basename($_files['attachment']['name']);

  • so in turn (and knew done), using temporarily stored file on server , attaching mail, automatically gets deleted once has been served/processed.

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -