附件电子邮件表格!?如何创建文件上传表单以通过电子邮件发送

发布于 2024-11-09 23:26:08 字数 422 浏览 5 评论 0原文

我一直在寻找这个,但找不到任何可以帮助我的表格!我不精通php,我需要为客户端创建一个表单,创建表单没有问题,但他们想要一个文件上传功能,它将文件作为附件发送,而不是将其上传到服务器。

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

有人可以帮忙吗!有没有任何“现成”的表格可供我使用?

谢谢!

编辑-请在此处阅读我的后续问题:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嘦怹 2024-11-16 23:26:08

我曾经使用过从 www.webmastercode.com 下载的 PHP 脚本,并且效果很好。以下是一个网站的链接,解释了它的作用:http://blogs.sitepoint.com/高级电子邮件-php/。希望这有帮助!

I've used a PHP script downloaded from www.webmastercode.com once, and it worked well. Here's a link to a site which explains what it does: http://blogs.sitepoint.com/advanced-email-php/. Hope this helps!

一身仙ぐ女味 2024-11-16 23:26:08

我认为 MIME 很适合用在这里。设置起来非常简单(只需一些includes()

// 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);

上面的代码要求您包含 MIME 扩展名,并且添加附件的最佳选择可能是上传文件,发送电子邮件,然后删除该文件。

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.

智商已欠费 2024-11-16 23:26:08

您可以制作一个临时上传文件 php 脚本并将更改放在表单中,以便将临时文件作为附件?

所以要上传临时文件

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?> 

,然后您可以将临时文件作为您的附件,所以......

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  $tempfile = ($_FILES["file"]["tmp_name"]);
  }
?> 

类似的东西?

大部分上传 php 脚本来自...

http://www.w3schools.com/PHP/ php_file_upload.asp

但其他人是斗鱼:-p

you could make a temp upload file php script and put the change the form so it will make the temp file as the attachment?

so to upload a temp file

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?> 

then you can make the temp file to be your attachment so...

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  $tempfile = ($_FILES["file"]["tmp_name"]);
  }
?> 

something like that?

got most of the upload php script from...

http://www.w3schools.com/PHP/php_file_upload.asp

but the other guys one is betta :-p

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文