0

我是 PHP 新手。我正在尝试将两个文件从表单上传到电子邮件中发送给自己。这可能很容易,但在过去三个小时内还没有做到。

如您所见,我已设法获取文件信息。你怎么附上这些?这就是我遇到麻烦的地方。

这是从表单接收两个文件(和其他数据)的代码。如果有帮助,该站点是 SermonPublish.com。

谢谢你的帮助。

标准获取变量。

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

获取有关文件上传的详细信息。

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

  }

好的,现在如何附加?

标准邮寄代码

    $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\n");

    echo "Thank you for your submission. We will contact you as soon as it is processed.";
  ?>
4

1 回答 1

0

我按照建议使用了 PHPMailer。效果很好。

于 2014-09-11T00:06:08.493 回答