duanlou7910 2016-08-16 21:40
浏览 6

文件上传字段附加文件到电子邮件

Have got a simple HTML form with file upload field:

    <form action="<?php bloginfo('template_url'); ?>/demo-contacts.php" method="post" id="sky-form" class="sky-form" enctype="multipart/form-data">
      <header>Submit an <strong>Application!</strong></header>
      <fieldset>
        <div class="row">
          <section class="col col-6">
            <label class="label">Name</label>
            <label class="input"> <i class="icon-append icon-user"></i>
              <input type="text" name="name" id="name">
            </label>
          </section>
          <section class="col col-6">
            <label class="label">E-mail</label>
            <label class="input"> <i class="icon-append icon-envelope-alt"></i>
              <input type="email" name="email" id="email">
            </label>
          </section>
        </div>
        <div class="row">
          <section class="col col-6">
            <label class="label">Telephone Number</label>
            <label class="input"> <i class="icon-append icon-phone"></i>
              <input type="text" name="telephone" id="telephone">
            </label>
          </section>
          <section class="col col-6">
            <label class="label">Address</label>
            <label class="input"> <i class="icon-append icon-envelope-alt"></i>
              <input type="text" name="address" id="address">
            </label>
          </section>
        </div>
        <section>
          <label class="label">Subject</label>
          <label class="input"> <i class="icon-append icon-tag"></i>
          <input type="text" name="subject" id="subject" value="Technician Application">
          </label>
        </section>
        <section>
          <label class="label">Covering Letter</label>
          <label class="textarea"> <i class="icon-append icon-comment"></i>
            <textarea rows="4" name="message" id="message"></textarea>
          </label>
        </section>
    <div class="row">
          <section class="col col-6">
            <label class="label">Attach your CV</label>
            <label class="input"> <i class="icon-append icon-file"></i>
              <input type="file" name="cv" id="cv">
            </label>
          </section>
    </div>
    <input type="hidden" name="recipient" value="<?php the_field('contact_form_recipient'); ?>">
      </fieldset>
      <footer>
        <button type="submit" class="button">Send</button>
      </footer>
      <div class="message"> <i class="icon-ok"></i>
        <p>Your message was successfully sent!</p>
      </div>
    </form>

And have the following PHP to process the form which worked well prior to adding file upload field:

$EmailFrom = "email address here";
$EmailTo = Trim(stripslashes($_POST['recipient']));
$Name = Trim(stripslashes($_POST['name'])); 
$Subject = Trim(stripslashes($_POST['subject'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Telephone = Trim(stripslashes($_POST['telephone'])); 
$Address = Trim(stripslashes($_POST['address'])); 
$Message = Trim(stripslashes($_POST['message'])); 
$CV = Trim(stripslashes($_POST['cv'])); 

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "
";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";
$Body .= "CV: ";
$Body .= $CV;
$Body .= "
";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL= URL here\">";
}
else{
  echo "failed";
}

At present, the e-mail that comes through just states the name of the file that's been uploaded, i'd like to have the file attached to the email, could someone guide me please?

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)