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

时间:2014-09-10 00:29:28

标签: php email-attachments mailing

我是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.";
  ?>

1 个答案:

答案 0 :(得分:0)

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