Search the Community
Showing results for tags 'attachment'.
-
So, I use mail() to send form data to a client. Works great. Now I am trying to send email to the same client, but with an attachment. I know PHPmailer is preferred, but I'm old school and would like to get this to work. The file I want to send as attachment gets to the far end, but Outlook email displays the binary data instead of having the pdf as an attachment attachment and looks like this: Attached is the Legal Description for 24050240--8f082344de8525de682e9d6aa86aa83f Content-Type: application/pdf; name="Testfile1.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Testfile1.pdf" JVBERi0xLjcNJcjIyMjIyMgNMSAwIG9iago8PC9OYW1lcyA4IDAgUi9PdXRsaW5lcyAyIDAgUi9U eXBlL0NhdGFsb2cvUGFnZXMgMyAwIFIvVmVyc2lvbi8xLjc+Pg0KZW5kb2JqCjIgMCBvYmoKPDwv VHlwZS9PdXRsaW5lcy9Db3VudCAwPj4NCmVuZG9iagozIDAgb2JqCjw8L0NvdW50IDEyL0tpZHNb OSAwIFIgNTAgMCBSIDc1IDAgUiA5OSAwIFIgMTI5IDAgUiAxNDUgMCBSIDE2OCAwIFJdL1R5cGUv UGFnZXM+Pg0KZW5kb2JqCjQgMCBvYmoKPDwvU3ViamVjdCgpL1Byb2R1Y2VyKEFzcG9zZS5QZGYg Zm9yIC5ORVQgOS4yLjEpL0NyZWF0aW9uRGF0ZShEOjIwMjQwMTI2MTE1NTQzKS9BdXRob3IoKS9N b2REYXRlKEQ6MjAyNDAxMjYxMTU1NDMpL0NyZWF0b3IoQXNwb3NlIEx0ZC4pL1RpdGxlKE11bHRp cGxlIERvY3VtZW50cyk+Pg0KZW5kb2JqCjggMCBvYmoKPDwvRGVzdHMgMTg0IDAgUj4+DQplbmRv ... ... more of this... The file size is 723709. Here is the code I am using: (I have some echo statements to help me trouble shoot.) Your help appreciated. function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { echo nl2br ("In funtion mail_attachment: filename = $filename\n"); $file = ($filename); echo nl2br ("In funtion mail_attachment: file = $filename\n"); echo nl2br ("In funtion mail_attachment: path = $path\n"); $file_size = filesize("$path/$file"); echo ("file_size = $file_size\n"); $handle = fopen($path.$filename, "rb"); echo ("handle = $handle"); //$content = file_get_contents($file); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); echo ("Content = $content\n"); $uid = md5(uniqid(time())); $eol = PHP_EOL; // Headers $header = "From: ".$from_name." <".$from_mail.">".$eol; $header .= "Reply-To: ".$replyto.$eol; $header .= "MIME-Version: 1.0".$eol; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\""; // // Message $header .= "--".$uid.$eol; $header .= "Content-type:text/plain; charset=iso-8859-1.".$eol; $header .= "Content-Transfer-Encoding: 8bit".$eol.$eol; //$message .= $body.$eol; $message .= "--".$uid.$eol; $message .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol; // use different content types here $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol; $message .= $content.$eol; $message .= "--".$uid."--"; if (mail($mailto, $subject, $message, $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!\n"; echo nl2br ("file = $file\n"); echo nl2br ("path.filename = $path.$filename\n"); } }
-
Hi! Any suggestions of how to set the // Set email variables & // simple email content for a checkbox to attach a copy of the message to the actual sender? In which case, I obviously do not know in advance to which email address this Cc attachment should be send... Anyone who can help me further? Thx
- 2 replies
-
- cc
- attachment
-
(and 2 more)
Tagged with:
-
http://independentrepublicofursum.tk/Become_a_Citizen/ is the page I am having trouble on. Basically what I want to happen here is for the user to download a fillable pdf application, fill it, and upload it. From there the php script will send it to my email so I can review it. My code is... function mail_file($to, $from, $subject, $body, $file) { $boundary = md5(rand()); $header = array( "MIME-Version: 1.0", "Content-Type: multipart/mixed; boundary=\"{$boundary}\"", "From: {$from}" ); $message = array( "--{$boundary}", "Content-Type: text/plain", "Content-Transfer-Encoding: 7bit", '', chunk_split($body), "--{$Boundary}", "Content-Type: {$file['type']}; name=\"{$file['name']}\"", "Content-Disposition: attachment; filename=\"{$file['name']}\"", "Content-Transfer-Encoding: base64", '', chunk_split(base64_encode(file_get_contents($file['tmp_name']))), "--{$boundary}--" ); mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers)); } Then to send it I use... if (isset($_FILES['file'])) { mail_file('myemail@gmail.com', 'ContactUs@independentrepublicofursum.tk', 'test subject', '', $_FILES['file']); } My form is... <form name="citizenship_application" action="" method="post" enctype="multipart/form-data"> First Name: <input type="text" name="first_name" value="<?php echo $first_name_value; ?>"> <br /> <br /> Last Name: <input type="text" name="last_name" value="<?php echo $last_name_value; ?>"> <br /> <br /> E-Mail:       <input type="text" name="e_mail" value="<?php echo $e_mail_value; ?>"> <br /> <br /> Gender:       <input type="radio" name="sex" value="male" <?php echo $male_pre_select; ?> >Male <input type="radio" name="sex" value="female" <?php echo $female_pre_select; ?> >Female <br /> <br /> <label for="file">Please specify your application file:</label> <br /> <input type="hidden" name="MAX_FILE_SIZE" value="501"> <input type="file" name="file" size="50"> <br /> <br /> <input type="submit" value="Submit Application" name="submit">  <?php echo $error; ?> </form> I get two errors, the first one is... Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/u418744221/public_html/Become_a_Citizen/index.php on line 38 Line 38 is... chunk_split(base64_encode(file_get_contents($file['tmp_name']))), My second error is... Warning: implode() [function.implode]: Invalid arguments passed in /home/u418744221/public_html/Become_a_Citizen/index.php on line 43 line 43 is... mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers)); Really need this finished, ASAP. I can't figure it out, any help appreciated thanks ya'll.
- 1 reply
-
- attachment
-
(and 3 more)
Tagged with:
-
Alright so I have use the PHP mail() function pretty extensively, however for my new site I will need to collect a filled fillable pdf file downloaded from my site, pull it from the files array, then send it to my e-mail so I can look at it later. I can do all of it except attach the .pdf file. How would I go about this? Please don't give me complete code because that is too easy. I wan't to figure it out myself but the tutorials simply don't explain what is happening.