你能通过电子邮件从网页发送文件吗?

时间:2010-01-27 12:28:26

标签: php javascript jquery

具有讽刺意味的是,对于IT承包商而言,我发现自己正在建立一个招聘咨询网站。

他们想要一个允许用户向他们发送简历的表单,但从安全的角度来看,将CV发送到电子邮件地址而不是存储在Web服务器上。有没有人知道jquery表单插件或其他类型的脚本是否可以这样做?

到目前为止,谷歌等没有运气。

先谢谢。

3 个答案:

答案 0 :(得分:2)

This页面解释了从文件上传到发送带附件的电子邮件

的所有内容

答案 1 :(得分:1)

<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test email with attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>

--PHP-alt-<?php echo $random_hash; ?>--

--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: application/zip; name="attachment.zip" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--

<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?> 

答案 2 :(得分:0)

让上传正常进入网络服务器上的临时文件夹,然后通过电子邮件发送该文件,然后将其删除。

否则,它只是告诉用户在他们的简历中发送电子邮件。我想不出任何直接将文件流重定向到邮件消息的方法。