繁体   English   中英

使用phpmailer和html表单发送带有附件的邮件

[英]send mail with attachment using phpmailer and html form

我正在尝试使用gmail smtp从一个发送邮件到另一个。 邮件已成功发送,但没有附件。 我该如何解决?

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 = "abc@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("feedback@abc.com");
$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("mymail@gmail.com");
 if(!$mail->Send()){
    echo "Mailer Error: " . $mail->ErrorInfo;
 }
 else{
    echo "mail sent";
  }
 ?>

此邮件已成功发送,但我希望它带有附件。 文件存储在目录中并不重要。 希望这个问题能立即解决。 在此先感谢,因为我之前从未学过使用过的php。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM