附件电子邮件表格!?如何创建一个文件上传表单以通过电子邮件发送 [英] Attachment email form!? How to create a file upload form to send with email

查看:179
本文介绍了附件电子邮件表格!?如何创建一个文件上传表单以通过电子邮件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为此寻找高低,并且找不到任何可以帮助我的形式!我不熟悉php,我需要为客户创建一个表单,创建表单没有问题,但他们需要一个文件上传功能,它将文件作为附件发送,而不是上传到服务器。



我在使用PEAR的网络上找到了一个,但我在使用共享主机帐户时遇到了很大的麻烦。

任何人都可以帮忙!是否有任何可以使用的表单?我可以使用这个表单吗?

谢谢!

编辑 - 请使用阅读我的后续问题:

https://stackoverflow.com/questions/6138979/adding-an-upload-file-field-to-a-php-form

解决方案

我在想MIME在这里可以使用。设置起来非常简单(只有一些 includes() s)

  //重要:将pdf内容添加为附件
$ filepath =('uploads / pdf /'。附件);
$ mime-> addAttachment($ filepath,'application / pdf',$ filepath,true,'base64');

//建立电子邮件并保存在$ body
$ body = $ mime-> get();

//构建标题
$ hdrs = $ mime->标题($ headers);

//创建稍后用于发送电子邮件的邮件实例
$ mail =& Mail :: factory('mail');

//根据$ to中的地址发送电子邮件,
// $ hdrs,
中的电子邮件标题以及$ body中的邮件正文。
$ mail->发送($ to,$ hdrs,$ body);

上面的代码要求您有MIME扩展名,并且最好的方法是添加一个attatchment上传文件,发送电子邮件,然后删除文件。


I've been searching high and low for this and can't find any forms that will help me! I'm not proficient with php and I need to create a form for a client, creating the form is no problem, but they want a file upload function which will send the file as an attachment NOT upload it to the server.

I found one on the net that uses PEAR but I was having big trouble getting it working on a shared hosting account.

Could anyone help please! Is there any forms "ready made" that I can use for this?

Thanks!

EDIT- PLEASE READ MY FOLLOW UP QUESTION HERE:

https://stackoverflow.com/questions/6138979/adding-an-upload-file-field-to-a-php-form

解决方案

I'm thinking that MIME is good to be used here. It's very simple to set up (just some includes()s)

// IMPORTANT: add pdf content as attachment
$filepath = ('uploads/pdf/'.$attachment);
$mime->addAttachment($filepath, 'application/pdf', $filepath, true, 'base64');

// build email message and save it in $body
$body = $mime->get(); 

// build header
$hdrs = $mime->headers($headers); 

// create Mail instance that will be used to send email later
$mail = &Mail::factory('mail'); 

// Sending the email, according to the address in $to,
// the email headers in $hdrs,
// and the message body in $body.
$mail->send($to, $hdrs, $body);

The above code requires that you have the MIME extension included and your best bet for adding an attatchment is probably to upload the file, send the email, then delete the file.

这篇关于附件电子邮件表格!?如何创建一个文件上传表单以通过电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆