doumengjing1500 2014-09-10 00:29
浏览 20

将两个文件从表单附加到电子邮件

I am a newbie with PHP. I'm trying to get two files that upload from a form into an email to send to myself. This is probably easy, but haven't got it the last three hours.

I've managed to get file information as you see. How do you attach these? That's where I'm having trouble.

This is the code that is receiving the two files (and other data) from the form.. The site is SermonPublish.com if that is helpful.

Thanks for any help.

Standard get the variables.

  <?php
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $cover = "cover: " . test_input($_POST["cover"]) . "
";
    $authorname = "Author Name: " . test_input($_POST["authorName"]) . "
";
    $booktitle = "Title: " . test_input($_POST["bookTitle"]) . "
";
    $subtitle = "Subtitle: " . test_input($_POST["subtitle"]) . "
";
    $description = "Description: " . test_input($_POST["description"]) . "
";
    $aboutauthor = "About Author: " . test_input($_POST["aboutAuthor"]) . "
";
    $clientnumber = "Client Number: " . test_input($_POST["clientNumber"]) . "
";
    $payment = "Payment: " . test_input($_POST["payment"]) . "
";
    $address = "Address: " . test_input($_POST["address"]) . "
";
    $agreement = "Agree: " . test_input($_POST["agreement"]) . "
";
    $email = test_input($_POST["email"]);

Get details about the file uploads.

        //Get the uploaded file information
      $author_photo_name =
          basename($_FILES['authorPhoto']['name']);
      $author_photo_type =
          substr($author_photo_name,
          strrpos($author_photo_name, '.') + 1);
      $author_photo_size =
          $_FILES["authorPhoto"]["size"]/1024;//size in KBs

      //Get the uploaded file information
      $sermon_name =
          basename($_FILES['sermon']['name']);
      $sermon_type =
          substr($sermon_name,
          strrpos($sermon_name, '.') + 1);
      $sermon_size =
          $_FILES["sermon"]["size"]/1024;//size in KBs

  }

Okay, now how do you attach?

Standard mailing code

    $subject = "Sermon Submission";
    $message = $cover . $authorname . $booktitle . $subtitle . $description . $aboutauthor . $clientnumber . $payment . $address . $agreement . $email;
    $message = wordwrap($message, 70);

    // send mail
    mail("wibberding@gmail.com",$subject,$message,"From: $email
");

    echo "Thank you for your submission. We will contact you as soon as it is processed.";
  ?>
  • 写回答

1条回答 默认 最新

  • dtsjq28482 2014-09-11 00:06
    关注

    I used PHPMailer as suggested. Works great.

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探