问题
I've been searching high and low for this and can't find any forms that will help me! I'm not proficient with php and I need to create a form for a client, creating the form is no problem, but they want a file upload function which will send the file as an attachment NOT upload it to the server.
I found one on the net that uses PEAR but I was having big trouble getting it working on a shared hosting account.
Could anyone help please! Is there any forms "ready made" that I can use for this?
Thanks!
EDIT- PLEASE READ MY FOLLOW UP QUESTION HERE:
https://stackoverflow.com/questions/6138979/adding-an-upload-file-field-to-a-php-form
回答1:
I've used a PHP script downloaded from www.webmastercode.com once, and it worked well. Here's a link to a site which explains what it does: http://blogs.sitepoint.com/advanced-email-php/. Hope this helps!
回答2:
I'm thinking that MIME is good to be used here. It's very simple to set up (just some includes()
s)
// IMPORTANT: add pdf content as attachment
$filepath = ('uploads/pdf/'.$attachment);
$mime->addAttachment($filepath, 'application/pdf', $filepath, true, 'base64');
// build email message and save it in $body
$body = $mime->get();
// build header
$hdrs = $mime->headers($headers);
// create Mail instance that will be used to send email later
$mail = &Mail::factory('mail');
// Sending the email, according to the address in $to,
// the email headers in $hdrs,
// and the message body in $body.
$mail->send($to, $hdrs, $body);
The above code requires that you have the MIME extension included and your best bet for adding an attatchment is probably to upload the file, send the email, then delete the file.
回答3:
you could make a temp upload file php script and put the change the form so it will make the temp file as the attachment?
so to upload a temp file
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
then you can make the temp file to be your attachment so...
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
$tempfile = ($_FILES["file"]["tmp_name"]);
}
?>
something like that?
got most of the upload php script from...
http://www.w3schools.com/PHP/php_file_upload.asp
but the other guys one is betta :-p
来源:https://stackoverflow.com/questions/6136041/attachment-email-form-how-to-create-a-file-upload-form-to-send-with-email