[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

Php form to send email with 2 attachments..

Asked by Rev22only in PHP and Databases

hello

i am trying to submit a form and send email with 2 attachments..

I am attaching the code I am trying.
I am getting files to attach from the following code.. where file1 and file2 are the file input tags

 $attachments[]=$_POST['file1']; // absolute file path here
$attachments[]=$_POST['file2'];

The code runs fine if the files are placed in root of the drive.. I think the file path is not posted
$attachments[0] holds only the file name but not the path..

How to make this work..
thanks..
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
<?php
$to = "xxx@gmail.com";
$from = "xxx@gmail.com";
$from_name = "Administrator"; 
$subject = "This is a test email";
$message = "Here is my message...Text or <b>HTML</b>."; 
$attachments = array();
$attachments[]=$_POST['coverletter']; // absolute file path here
$attachments[]=$_POST['resume']; 
mail($from, "Responding subject", "", "From: Responder Name "); 

function send_email($to, $from, $from_name, $subject, $message, $attachments=false)
{
$headers = "From: ".$from_name."<".$from.">\n";
$headers .= "Reply-To: ".$from_name."<".$from.">\n";
$headers .= "Return-Path: ".$from_name."<".$from.">\n";
$headers .= "Message-ID: <".time()."-".$from.">\n";
$headers .= "X-Mailer: PHP v".phpversion(); 
$msg_txt="";
$email_txt = $message; 
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\""; 
$email_txt .= $msg_txt; 
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n"; 

if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]))
{
$fileatt = $attachments[$i];
$fileatt_type = "application/octet-stream";
$start= strrpos($attachments[$i], '/') == -1 ? strrpos($attachments[$i], '//') : strrpos($attachments[$i], '/')+1;
$fileatt_name = substr($attachments[$i], $start, strlen($attachments[$i])); 
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file); 
$data = chunk_split(base64_encode($data)); 
$email_message .= "--{$mime_boundary}\n" .
                        "Content-Type: {$fileatt_type};" .
                        " name=\"{$fileatt_name}\"\n" .
                        "Content-Transfer-Encoding: base64\n" .
                        "Content-Disposition: attachment; filename=\"{$fileatt_name}\"\n\n" .
                        $data . "\n\n" ;
						 
}
}
} 
$email_message .= "--{$mime_boundary}--\n"; 
return mail($to, $subject, $email_message, $headers);
} 
?>
[+][-]11/06/09 12:33 AM, ID: 25757538Accepted Solution

Your question has an Asker Certified™ answer! Rev22only verified that this solution worked for them--which means it will likely work for you, too. Click to view the solution free for 30-days now.

About this solution

Zone: PHP and Databases
Sign Up Now!
Solution Provided By: Rev22only
Participating Experts: 2
Solution Grade: A
 
[+][-]11/05/09 01:07 AM, ID: 25747739Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:08 AM, ID: 25747748Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:34 AM, ID: 25747860Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 02:03 AM, ID: 25747985Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 02:04 AM, ID: 25747988Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/05/09 02:18 AM, ID: 25748053Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 02:21 AM, ID: 25748065Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 09:41 AM, ID: 25751910Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 09:57 AM, ID: 25752057Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/09 02:37 AM, ID: 25784050Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20100308-EE-VQP-132 - Hierarchy / EE_QW_3_20080625