将附件添加到联系表Phpmailer

时间:2018-12-17 20:19:11

标签: php html twitter-bootstrap email-attachments

我有一个联系表,可以发送到不同的电子邮件或部门,并且效果很好。我想为用户添加附加文件并发送电子邮件的功能。有没有图书馆phpmailer的方法,或者我可以在当前的php文件中添加代码以添加附件吗?

HTML附件:

  <div class="form-group second-row">
                  <p><label><span class="attachment">Attachment </span> <input type="file"  class="form-control" id="fileMain" name="attachment"></label></p>

              </div>

当前PHP:

<?php
$subject= $_POST['subject'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$emailc = $_POST['emailc'];
$organization = $_POST['organization'];
$phone = $_POST['phone'];
$zip = $_POST['zip'];
$contactmethod = $_POST["contactmethod"];
$message = $_POST['message'];

if(isset($_POST['state'])){
    $state=$_POST['state'];
 }

 else{
    echo "Not set.";
 }



$email_from = 'email';
$email_subject = 'New';
$email_body = "Subject: $subject.\n".
            "First Name: $firstname.\n".
              "Last Name: $lastname.\n".
              "Email: $email.\n".
              "Email Confirmation: $emailc.\n".
              "Company: $organization.\n".
              "Phone: $phone.\n".
              "State: $state.\n".
              "Message: $message.\n";
              "Contact Method: $contactmethod.\n".


   $to ="email.com";
   $headers = "From: $email_from \r\n";
   $headers .= "Reply-To: $email \r\n";

mail($to,$email_subject,$email_body,$headers);

header("location: thankyou.html");
?>

0 个答案:

没有答案