发送附件使用phpmailer和HTML格式的邮件

问题描述:

我想从一个邮件发送到其他使用Gmail邮件。 邮件发送成功但没有附件。我该如何解决这个问题?发送附件使用phpmailer和HTML格式的邮件

HTML表单:

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendresume.PHP" enctype="multipart/form-data"> 
       <div class="row"> 
        <div class="col-sm-5"> 
         <div class="form-group"> 
          <input type="text" name="name" class="form-control" required="required" placeholder="Name"> 
         </div> 
         <div class="form-group"> 
          <input type="text" name="mobile" class="form-control" required="required" placeholder="Mobile number"> 
         </div> 
         <div class="form-group"> 
          <input type="email" name="email" class="form-control" required="required" placeholder="Email address"> 
         </div> 

         <p class="lead" style="margin-bottom: 10px;">Resume :</p> 
         <div class="form-group"> 
          <input type="file" name="file" class="form-control" required="required" > 
         </div> 

         <div class="form-group"> 
          <button type="submit" class="btn btn-primary btn-lg">Send Message</button> 
         </div> 
        </div> 
        <div class="col-sm-7"> 

         <textarea name="messege" id="message" class="form-control" rows="8" placeholder="Note"></textarea> 

        </div> 

       </div> 
      </form> 

和PHP代码为:

<?php 
include "classes/class.phpmailer.php"; // include the class name 
$email = $_POST["email"]; 
$messege=$_POST['messege']; 
$name=$_POST['name']; 
$mobile=$_POST['mobile']; 
$mail = new PHPMailer(); // create a new object 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "mypassword"; 
$mail->SetFrom("[email protected]"); 
$mail->Subject = "this is subject"; 
$mail->Body = "this is body <br/><br/><br/><br/> 
name:$name <br/><br/> 
email:$email<br/><br/> 
mobile:$mobile<br/><br/> 
messege:$messege</b>"; 

$mail -> Addattachment('here is problem'); 

$mail->AddAddress("[email protected]"); 
if(!$mail->Send()){ 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else{ 
    echo "mail sent"; 
    } 
?> 

此邮件发送成功,但我和附件想要它。目录中的文件存储并不重要。希望立即解决这个问题。在此先感谢,因为我从来没有学过一个使用过的PHP。

+0

你试过回声的文件路径?可能是附件从未设置发送 – 2014-10-31 12:19:12

+0

,正如我所说的问题,我不知道任何关于PHP。你能举个例子 – 2014-10-31 12:26:21

+0

好的,请先'echo $ filepath;'(附件)并检查文件路径是否正确。 (注释邮件部分) – 2014-10-31 12:30:38

+0

不够。需要html表单。 – atilkan 2015-08-14 18:22:34

+0

@emrah这个论坛是为了帮助,只是与我分享你在做什么? – 2015-08-15 16:18:55

+0

该页面已过时,并且与当前的PHPMailer存在问题。 PHPMailer提供的示例和文档更全面且最新。 – Synchro 2015-10-31 13:54:11