...

View Full Version : Upload file and send file via email attachment



jhaydon
05-16-2011, 09:32 PM
I need an easy to use script that will allow site visitor to upload file and then send file to client via email attachment. It will be placed within a form file that is already written. Any and all help is greatly appreciated. Thank you!

Fou-Lu
05-16-2011, 10:49 PM
Search google/sourceforge for PHPMailer, and follow its documentation for implementing it. That should do what you need.

jhaydon
05-17-2011, 01:12 AM
Search google/sourceforge for PHPMailer, and follow its documentation for implementing it. That should do what you need.

Thank you, however, that is not what I am needing. I may not have been very good in describing what I need.

Here is what I have:


<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Quote Form';

// Your email address. This is where the form information will be sent.
$emailadd = 'my@email.com';

// Where to redirect after form is processed.
$url = 'http://www.mydomain.com/thankyou.html';

// Where to direct file upload.
$file= 'http://www.mydomain.com/upload/';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';{
}
if ((($_FILES["file"]["type"] == "application/ai")
|| ($_FILES["file"]["type"] == "application/cdr")
|| ($_FILES["file"]["type"] == "application/dxf")
|| ($_FILES["file"]["type"] == "applicationj/eps")
|| ($_FILES["file"]["type"] == "application/pdf"))
&& ($_FILES["file"]["size"] < 900000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

I have changed my email and domain name in the above script for display purposes. What I need to have happen is for the file that is uploaded to also be sent with the email that sends the rest of the information from the form. I hope this helps to better understand what I am asking.

Fou-Lu
05-17-2011, 01:32 AM
I'm aware of what you need. PHPMailer is a package designed for easy implementation for things such as html and attachments. Attachments in particular are tricky when using a mail command in PHP.
You will need to rewrite it to implement it into what you are trying to do. You won't get a handout here, but if you are looking for this to be done for you I'd suggest posting within one of the paid forum requests.

jhaydon
05-17-2011, 02:15 AM
I'm aware of what you need. PHPMailer is a package designed for easy implementation for things such as html and attachments. Attachments in particular are tricky when using a mail command in PHP.
You will need to rewrite it to implement it into what you are trying to do. You won't get a handout here, but if you are looking for this to be done for you I'd suggest posting within one of the paid forum requests.

Wow, I'm sorry! I wasn't looking for a handout, just a little help. Forgive me for even asking. Guess this forum isn't for helping like others are. BTW, you didn't have to be so rude about it.

Fou-Lu
05-17-2011, 03:33 AM
I don't consider what I've told you to be rude, merely practical. I see a lot of requests that are essentially for handouts.
You have asked for a script that can handle your attachments, and I have suggested that you use PHPMailer. You simply need to write the interface on top of it which is simply what you already have and replace the mail handling with the PHPMailer classes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum