当提交为电子邮件时,PHPmailer不会从表单附加文件

时间:2014-06-25 16:04:19

标签: php forms email attachment

我正在尝试构建一个带有广播和文本输入的表单,还有一个文件上传,我希望将其附加到表单生成和发送的电子邮件中。

我已经尝试了很多不同的方法来实现这一点,但没有一个可行,我可以收到所有信息发送的电子邮件,但附件,我无法看到我做错了什么,任何帮助将不胜感激。< / p>

这是网络表单(html):

  <form id="form1" enctype="multipart/form-data" action="submit/applicationscript.php" method="post" name="form1">

  <input checked type="radio" name="school" value="English Martyres"/>

  <input type="radio" name="stop" value="stop1" />              
  <input type="radio" name="stop" value="stop2" />
  <input type="radio" name="stop" value="stop3" />
  <input type="radio" name="stop" value="stop4" />

  <input type="checkbox" name="mon" value="Monday" />
  <input type="checkbox" name="tue" value="Tuesday" />
  <input type="checkbox" name="wed" value="Wednesday" />
  <input type="checkbox" name="thu" value="Thursday" />
  <input type="checkbox" name="fri" value="Friday" />

  <input type="text" class="text" name="name" required placeholder="First Name" /></div>
  <input type="text" class="text" name="surname" required placeholder="Surname" /></div>
  <input type="text" class="text" name="dob" required maxlength="10" placeholder="Date of Birth" />
  <input type="file" name='uploaded_file' required />

  <input type="submit" id="form1" name="submit" value="Submit" onClick="document.form1.submit()">

   </form> 

这是PHP:

<?php

    $school = $_POST['school'];
    $stop = $_POST['stop'];
    $mon = $_POST['mon'];
    $tue = $_POST['tue'];
    $wed = $_POST['wed'];
    $thu = $_POST['thu'];
    $fri = $_POST['fri'];
    $name = $_POST['name'];
    $surname = $_POST['surname'];
    $dob = $_POST['dob'];
    $file_to_attach = $_POST['uploaded_file'];

    $bodytext = <<<EOD
School: $school \n
Stop: $stop \n
Days: $mon $tue $wed $thu $fri \n
Name: $name $surname \n
DOB: $dob \n
Photo ID: $file \n
EOD;

    require("phpmailer.php");

    $email = new PHPMailer();
$email->From      = 'info@ausdenclark.co.uk';
$email->FromName  = 'Ausden Clark';
$email->Subject   = 'Schooltravel Application';
$email->Body      = $bodytext;
$email->AddAddress( 'd.o.m.d@hotmail.com' );

$email->AddAttachment( $file_to_attach , 'uploaded_file' );

return $email->Send();

?>

我想象一些非常愚蠢和简单的事我做错了!

0 个答案:

没有答案