grats
2012-05-10 09:41:23
So I can't use PEAR library because bad server is bad, anyways..
I have a contact us setup for this company they also wanted a job application up there, with most of the same stuff as the contact us except they also want a place to attach something such as a resume to the email
I figure something like browse to the file select it
the server takes the file when it uploads to the temp directory and it attaches it to the email and then would send the email, (and then the temp directory auto deletes the uploaded file like normal)
not sure how I would go about grabbing the temp file and attaching it to an email in PHP, I have found some different codes but they seem to require PEAR library (which I have on my server, but their host doesn't have…)
Greatly appreciated
masterBB
2012-05-10 09:44:31
I always used
http://swiftmailer.org/, but I am not sure if that helps you.
grats
2012-05-10 09:52:09
From: masterBB
I always used http://swiftmailer.org/, but I am not sure if that helps you.
Thanks but looks like it requires PEAR(which is the main email library for PHP) someone around here probably knows a quick piece of code that just grabs temp file and attaches to email, looking at upload code I've done before it will probably be like 5-10 lines of code only, I just have no idea how to attach to an email lol
Frement
2012-05-10 10:32:31
Wrote this for you :)
[PHP]<?php
/*
Edit your variables here.
*/
$filePath = "/path/to/my/file/";
$fileName = "uploadedFile.doc";
$emailFrom = "someone@example.com";
$emailTo = "anybody@another.com";
$emailSubject = "Email with attachment!";
$emailMessage = "Open the attachment you mortal!";
$emailCharset = "utf-8";
/*
Don't touch here.
*/
$fileInfoHandle = finfo_open(FILEINFO_MIME_TYPE);
$fileType = finfo_file($fileInfoHandle, $filePath.$fileName);
finfo_close($fileInfoHandle);
$fileData = chunk_split(base64_encode(file_get_contents($filePath.$fileName)));
$mimeBoundary = "==Multipart_Boundary_x".md5(time())."x";
$emailHeader = "From: ".$emailFrom.PHP_EOL;
$emailHeader .= "MIME-Version: 1.0".PHP_EOL;
$emailHeader .= "Content-Type: multipart/mixed; boundary=\"".$mimeBoundary."\"".PHP_EOL;
$emailRealMessage = "This is a multi-part message in MIME format.".PHP_EOL.PHP_EOL;
$emailRealMessage .= "–".$mimeBoundary.PHP_EOL;
$emailRealMessage .= "Content-Type: text/html; charset=\"".$emailCharset."\"".PHP_EOL;
$emailRealMessage .= "Content-Transfer-Encoding: 7bit".PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL;
$emailRealMessage .= $emailMessage.PHP_EOL.PHP_EOL;
$emailRealMessage .= "–".$mimeBoundary.PHP_EOL;
$emailRealMessage .= "Content-Type: ".$fileType."; name=\"".$fileName."\"".PHP_EOL;
$emailRealMessage .= "Content-Transfer-Encoding: base64".PHP_EOL.PHP_EOL;
$emailRealMessage .= $fileData.PHP_EOL.PHP_EOL;
$emailRealMessage .= "–".$mimeBoundary."–".PHP_EOL;
$mailSent = mail($emailTo, $emailSubject, $emailRealMessage, $emailHeader);
/*
Ok, you can touch again.
*/
if ($mailSent) {
echo "Congratulations! You've sent an email!";
} else {
echo "Oops! Something went wrong.";
}
?>[/PHP]
EDIT: Sec :)
EDIT2: Ok, bug fixed.
grats
2012-05-10 11:48:15
For example:
http://www.w3schools.com/php/php_file_upload.aspWhen they upload the files it goes into a temp directory
would we use something like $_FILES["file"]["tmp_name"] to pull from that temp directory and attach to the email? that's another part where I'm confused, going to try it out now that I'm not busy
Frement
2012-05-10 12:21:44
You can use
move_uploaded_file() to copy the file to your temp directory (if you want to keep the file for a while.
Then after sending the email, to delete the file, use this:
unlink()
grats
2012-05-10 12:24:34
Well it is automatically deleted unless it's moved from the temp file, so I figured it could be added to the email and sent and then it would just do its usual auto deletion
talking to one of the CEO's right now they're so beyond confusing I don't even know if they want this stuff anymore, but I'd still like to learn it
uhg now the two guys are saying different shit, brb going to drive there real fast
Frement
2012-05-10 12:26:34
Well, anyway, theres everything you need :) Have fun coding!