Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

attach file to email using php

I have an input on my form to allow a user to browse to a file location. The idea being that they can attach a resume to to the application they are getting ready to submit.

<label class="description" for="element_5">Upload a File </label>
        <div>
            <input id="element_5" name="element_5" class="element file" type="file"/> 

For my text feilds and dropdowns I have been using something along the lines of:

$experince = $_POST["experince"];

But I don't want the path string i want the actual file. How do I get the file itself and how do I attach it to the email?

Also, is there a easy way to limit the attachment to .DOC / .PDF?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I did something similar to this recently. It is not trivial.

Your email message will have to be a multipart Mime message. You will read in your file, encode it (using base64), then place it in your email message string in the correct spot.

This looks like a decent tutorial (that I wish I had found before): http://www.texelate.co.uk/blog/send-email-attachment-with-php/

But note that the tutorial has some escape issues:

$message . "“nn";

should be:

$message . "

";

You can also look into the Mail_Mime PEAR package for help: http://pear.php.net/package/Mail_Mime


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...