DogEater008
Oct 21 2005, 04:38 AM
| | i know there are a few topics talk about attachment problem, but i want to know if anyone could show me a basic code for attaching files like pictures with the message.
I made a html form, and redirect the information to my mail.php file to process the information and send it to my email. I want to know what do i have to do to attach files like pictures. I tried to search on google, and the codes are so complicated (i'm an amateur at this). Would it be possilbe if you could show me the code and explain to me what it does and how i could customize it to fit my needs?
thankyou
|
Reply
DogEater008
Oct 22 2005, 09:41 PM
CODE // In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of // $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_file() // instead of move_uploaded_file
$uploaddir = '/public_html/site/html/uploads/'; $uploadfile = $uploaddir. $_FILES['userfile']['name'];
print "<pre>"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { print "File is valid, and was successfully uploaded. "; print "Here's some more debugging info:\n"; print_r($_FILES); } else { print "Possible file upload attack! Here's some debugging info:\n"; print_r($_FILES); } print "</pre>"; i found that code and when i tried to exacute the php file, it said Possible file upload attack! Here's some debugging info: Array ( [attachment] => Array ( [name] => logo.jpg [type] => image/jpeg [tmp_name] => /tmp/phpmlM3po [error] => 0 [size] => 20655 ) ) i tried to give my folders full permission and it still doesn't work. and how can I attach the uploaded file(s) to an email
Reply
DogEater008
Oct 23 2005, 02:57 AM
ok.. i think i got the file to upload to my tmp folder ( i think because when i exacute the .php file , i got the message CODE File is valid, and was successfully uploaded. Here is some more debugging info:Array ( [attachment] => Array ( [name] => logo.jpg [type] => image/jpeg [tmp_name] => /tmp/phpvzOMho [error] => 0 [size] => 20655 )
). [/CODE
So i'm guessing it works. NOw.. my question is.. how am i suppose to embed that into my mail.
[CODE] <? $name=$_POST['name']; $email=$_POST['email']; $attachment= $to="example@gmail.com"; $message="Terms and Conditions: $agree \nName: $name Middle:$middle \nAge: $AGE \nDate of Birth: $month $date, $year \nWeight: $weight Pounds \nHeight: $height Inches \nAddress: $address $city, $state $code \nTelephone: $phone \nEmail: $email \nSchool: $school \nMajor: $major \nAbout $name \n $reason"; if(mail($to,"Application from $name",$message,"From: $email\n")) { echo "Thankyou for registeringt"; } else { echo "There was a problem sending the mail. Please check that you filled in the form
correctly. Please Click Back"; }
i dont' really know what i'm doing exactly. So please help me out. It seems like no one is bothering to help. =(
Reply
Lozbo
Feb 7 2006, 11:58 PM
Hi dog eater, I find myself in the same problem as you. I tried looking a little bit in google and php dot net but Im also an amateur... I have a working php sendmail script, which I adapted from different stuff I found here and there, I didnt write the whole thing but I made the final mix... I know (guess you already know this too) how to send mail, the most basic line to achieve so is this: mail($admin_mail, $subject, $content, $headers) Where admin mail is the mail you want the message to be sent, and the headers are additional information which is optional. Subject and Content I think that are obvious. But the command to attach a file is what is missing, and I dont know either how to do it... Hope someone could help us both.. thanks in advance Ill keep browsing the web for it but would apreciate a lot yer help...
Reply
Tyssen
Feb 8 2006, 12:20 AM
Make sure you're cleaning any input before sending it to your mail function.
Reply
Lozbo
Feb 8 2006, 01:18 AM
How is that? cleaning any input? You mean from the html form itself? Could you teach us how to do so? Thanx a lot Tyssen, but Im not sure if this is a tip for sending secure mail through php or actually about the thread's topic... I mean no offense...
Reply
Tyssen
Feb 8 2006, 05:09 AM
Well it doesn't necessarily relate to the topic of adding email attachments, but whenever you're using a HTML form to transmit info to your mail program via PHP, you need to be aware of the danger of 'email header injection'. A Google search on that will provide you with more and better info than I could give here.
Reply
kvkv
Feb 8 2006, 07:22 PM
Here you go. Use this opensource code to send your mails. http://phpmailer.sourceforge.net/
Reply
Lozbo
Feb 9 2006, 02:10 AM
Thanx Tyssen its a nice tip ill google it... And kvkv thanx for that link, ill give it a try, i havent tested it yet but the main page displays this as a feature: Multiple fs, string, and binary attachments (those from database, string, etc) Im not sure if it is what i need, do you know something about it? I dont want to upload files to a database but to send them right through the form... thanks a lot!
Reply
Hamtaro
Feb 25 2006, 06:16 AM
I'm a little late with this, but I can show you how I did it (after doing a lot of searches from Google). It's a little more simpler. However, one limitation of the code I'm going to give, is that it supports only gif or jpg images. Should you want to add more, it's easy to do, but you need to know the mime type for the file. CODE //Gather file data and other things $tmp = $_FILES['sample']['tmp_name']; $sep = md5(time()); $filename = $_FILES['sample']['name'];
$filedata = file_get_contents($tmp); //Get file contents $fdata = chunk_split(base64_encode($filedata)); //Encode data into text form
$to = "you@domain.com"; //Email address to send this to
//Determine mime type $ext = explode('.', $filename); $ext = $ext[1];
if($ext == "JPG" || $ext == "jpg" || $ext == "JPEG" || $ext == "jpeg") { $mime_type = "image/jpeg"; } elseif($ext == "gif" || $ext == "GIF") { $mime_type = "image/gif"; } else { exit("Error: Wrong file type!"); }
//Begin the message. Be sure to change this how you want it. $message = "Email message here";
//Begin the headers $headers = "From: \"From Name\" <{$email}> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary=\"$sep\"
charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit
--$sep Content-Type: $mime_type; name=\"$filename\" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=\"$filename\"
$fdata --$sep";
$subject = "Email Subject Here"; mail($to, $subject, $message, $headers); One last limitation: Files with more than one . in them may not be processed completely right (I've not tested it that much). I don't know exactly how to get the extension. I don't know just how many files you'll get with more than one in it, though. I will now explain it to you. The file sending is actually done using the mail headers. However, the message has to be converted to base64 encoding (which will send it as text). This is done by first getting the contents of the file using file_get_contents() then chunk_split() and base64_encode(). The chunk_split() converts the text to match RFC 2045 semantics (that way the email client will be able to read the base64 encoded file). Oh, and remember where it says $_FILES['sample'] change 'sample' to the name of the file upload field (just reminding you). Also, the $email in the headers should be changed to whatever you want the From part to be. I have tested this code many times, and it works the way it should. However, you still need to include your form, and add whatever data you're going to send in the message. If you want to send other types of files, you just add more after the elseif. Such as: CODE if($ext == "JPG" || $ext == "jpg" || $ext == "JPEG" || $ext == "jpeg") { $mime_type = "image/jpeg"; } elseif($ext == "gif" || $ext == "GIF") { $mime_type = "image/gif"; } elseif($ext == "bmp" || $ext == "BMP") { $mime_type = "image/bmp"; //I think that's the mime type for BMP files } elseif($ext == "txt" || $ext == "TXT") { $mime_type = "text/plain"; } else { exit("Error: Wrong file type!"); } One last note: I know the mime_content_type() function gives me the mime type, but I had some problems with it. Anyway, this method also ensures that you get only the file types that you want. Also, I used the file extension in both lowercase and caps to ensure that it would be sent. I know that sometimes the file extensions get capitalized automatically for some reason in Windows. I hope this helped you. If I need to explain anything more, please let me know.
Reply
Latest Entries
iGuest
Jul 15 2008, 08:23 PM
please can u give me the code for sending an file attachment in send mail function
Form To Php Mail. Attachment
I tried very much for the specific code but in vain. Please provide me the exact code to do so. Thank you, Pritish -reply by pritish
Reply
iGuest
Jun 20 2008, 07:16 PM
Thank for the articles of (PHP Mail with Attachment)
Form To Php Mail. Attachment
This articles help me a lot. Thank for it. -feedback by smithveg
Reply
iGuest
May 15 2008, 11:36 PM
Thanks for a beautiful site! I have added you in elected! http://cbnch.Icr38.Net -reply by Anne
Reply
iGuest
Apr 6 2008, 05:37 AM
response, its easy
Form To Php Mail. Attachment
Just so you guys know if you send the file through a form submit, the $_FILES['userfile']['type'] contains the MIME type information, just send that variable to the header for a quick solution... Encoding is different though... There might be a good encoding format that will work for just about anything your sending... Not sure though
Reply
Recent Queries:--
sendmail.php upload attach picture - 0.68 hr back. (1)
-
attaching file in email with php mail form - 0.80 hr back. (1)
-
sendmail.php attach picture - 0.70 hr back. (2)
-
php form mail attachment - 5.76 hr back. (1)
-
attach image php mail - 6.11 hr back. (1)
-
contact form with attach php script - 6.22 hr back. (1)
-
php mail with attachment - 6.47 hr back. (1)
-
email attachment php - 7.19 hr back. (1)
-
php email multi attachments images - 8.44 hr back. (1)
-
attach zip file php mail function - 8.68 hr back. (1)
-
php html form attachments - 10.77 hr back. (1)
-
php mail attachments gif - 11.27 hr back. (1)
-
php email attach - 11.35 hr back. (1)
-
php email image attachment - 11.67 hr back. (1)
Similar Topics
Keywords : form, php, mail, attachment
- Requirements For Mail()
(2)
Php Functions To Send Mail
(4) Which other methods to send mail from a form? I just know mail function, like: mail(string to,
string subject, string message) Has anyother?....
Prequirement For Mail()
(1) I'm asking because I often see so many books told me to use mail() feely, but I don't really
understand. Can we really use this without even have a mail server or anything related to that? Or
even if we need something before using this function, can anyone tell me waht those are? Right now
my website had not have this function yet, but I'm trying to, because it's necessary
sometimes when I got another project.....
Mail() Clone
A PHP mail() function clone (5) A lot of free web hosts have disabled the mail() function so you cannot send emails using PHP. Does
anybody know of a script that makes a function "like" mail but is able to be installed in a web
accessible directory and called included into another script and called like that? Or maybe you know
how to make such a function? I just really need to find a way around the free hosts turning of the
mail() function. I need to figure out a way to send emails.....
Want To Send Mail But Smtp Disabled, Help Me!
(7) heyy...I have a problem, I have an account in another hosting service, but the SMTP and sendmail
was disabled for my account. and I want to send mail to all people who join my site (with php script
to send that mail), so I can't send mail to them. for more information, my operating sistem is
Linux and php version 4.4.1. I hear when drupal send e-mail without SMTP, is that true??? and can
I send mail when I already installed Drupal in my hosting service???? Please give me solution,
how can I send an e-mail when my sendmail and SMTP disabled!!!!....
Wappymail_v1.50
wap free mail/ email admin script :-) (15) Here is my new wap mail script. You can use it as a free email sending service or an email admin
form (can set this option in config.php) its extremly simple to install and you will find full
instructions in the zip file. Please feel free to comment, rate, or update this script :-)
/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> ....
Bulk Mail
How to do that (5) Hey , I have a problem . I wanted a script to send emails using PHP to more than 5000 email
addresses for my software. But if you use the regular mail() function it will cause tremendous
overload o the servers. I tried searching on the net but no use and i found some pre-built ones
which are either copyrited or using PHP 5 only. But I want to make my own function to send Bulk
Mails. If someone could give me a start I would be thankful. So does any one know how to send
bulkmail. Also I needed to give an option of using SMTP servers if PHP mail is not supported on....
Help With Mail And Attachments
Help on mail attachments (4) Hi, can someone please give me an example of how to send a zip or other filetype as an attachment
using the mail() command? Im also interested in sending to mail email address, for example i have a
.txt file full of email addy's like: mail1@blah.net mail2@blah.net mail3@blah.net how can i send
the file and or mail to all these addy's in one go? Mmm......
Question About The Mail() Function
(2) Hi, Is there any way of using the mail() function with an SMTP connection? Is there any way of
sending messages let's say for example using an email of yahoo? Any help about this woul be very
thankfull. Thanks in advance.....
How To Enable Mail() Function In Php
(1) im just trying to send mail by using a very simple php function mail() but it is not working.the
format is CODE $to = "email@example.com"; $subject = "Hi!";
$body = "Hi,\n\nHow are you?"; if (mail($to, $subject,
$body)) { echo("<p>Message successfully
sent!</p>"); } else { echo("<p>Message delivery
failed...</p>"); } I think there is something wrong with php.ini
setting..maybe something to do with SMTP ....
Send Mail In Strict Xhtml
form elements atribute Name (2) Im using xhtml strict, and trying to send a form to 'mail.php' which actually sends the
data, but it seems that php does not detect the $_POST ; if i do not assign a "name" attribute
in the form, but strict xhtml does not accept the name attribute in my form elements... When i try
to validate, it says... "there is no name attribute" and stuff... and what i say is yeah yeah
whatever you perverse Markup Validation Service, i knew that... but php does not recognize an id
attribute to use with $_POST so i can not send info, or tell me if i'm wrong? Wha....
Build Contact Mail
(3) Hi I Write One Contact Mail and i want to share with u at first File index.htm : in this file
build one form and post this form to and i find this php code on internet you can use this for
send mail : CODE <?php $MailToAddress = "Here"; // your email address
$redirectURL = "So Example Final.htm :blink: "; // the URL of the thank you
page. # optional settings $MailSubject = "Sample"; // the subject of the email
$MailToCC = "Back UP Mail"; // CC (carbon copy) also send the email to th....
Php G-mail Login
Compatable on all browsers (8) I fount a PHP G-mail login script to login to your g-mail using any browser. Even IE1, I installed
it on my site at http://www.gmail.mbd5882.trap17.com/ I tested it myself, Its safe. gmail-lite is
an html-only interface of GMail. It was develope it with PDA browser (mostly Netfront) in mind, it
should be workable with any browser on Earth (e.g. lynx, ie3, netscape4, opera5. The only tags being
used are A, B, FORM, H1, I, INPUT, P, SELECT, TEXTAREA, TABLE, TR, and TD (and META and STYLE in
HEAD). It alows you to send 10 invites at once and is fast. It uses cookies i, An....
Contact Form
Contact form using mail() function (2) In first place, make an html page with the form. My first form with PHP Name:
E-Mail: Subject: Mesage: OK, now, lets make
sendmail.php: $myemail = 'yourmail@blah.com'; // Put here your e-mail address
mail($myemail,$subject,$mesage,$email) // To, Subject, Mesage and From echo
'Thank you for your e-mail!'; ?> Simple, huh? Any questions just post here.....
Php Mail Script Wont Work :(
(8) My script wont work and I cant figure out where I did go wrong The form looks like this: CODE
<form name="member-request" action="index.php?page=request"
method="post"> <p><b>Gender:</b></p>
<ul> <input type="radio" name="gen" value="1" />Male
<input type="radio" name="gen" value="2" />Female </ul>
<p><b>Your Name:</b></p> <p><input
type="text....
Multi-mail
(4) Hi ! I'd need to create a PHP script that would allow me to send an e-mail to many persons
at the same time (newsletter). All the e-mail adresses are ine a MySQL database. So how do I do with
the function mail() to send many e-mails ? Do I use loops or maybe an array ? But how to put the
MySQL request in an array ? Please help me. Thanks in advance.....
Looking for form, php, mail, attachment
|
|
Searching Video's for form, php, mail, attachment
|
advertisement
|
|