dongyinting3179 2017-06-21 12:34
浏览 85
已采纳

PHPMailer附件不起作用

i added the upload file function in phpmailer function when i want to send file, it only showing name of file, actual file is missing in attachment.

is there any idea to solve this problem. Any help will be appreciated.

Looking for help

<?php

if(isset($_POST['submit'])) 
{

$message=
'Full Name: '.$_POST['fullname'].'<br />
Subject:    '.$_POST['subject'].'<br />
Phone:  '.$_POST['phone'].'<br />
Email:  '.$_POST['emailid'].'<br />
Attachment: '.$_POST['attachment'].'<br />
Comments:   '.$_POST['comments'].'
';


require 'PHPMailer/PHPMailerAutoload.php';






$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'lijojohn004@gmail.com';                 // SMTP username
$mail->Password = '******';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to




$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "New Contact Form Enquiry";      // Subject (which isn't required)  
$mail->MsgHTML($message);

$mail->addAttachment('attachment');         // Add attachments
$mail->isHTML(true);   
 
 
 

    $mail->addAddress('lijomattathil@gmail.com', 'Website');     // Add a recipient
    $result = $mail->Send();     // Send!  
    $message = $result ? 'Successfully Sent!' : 'Sending Failed!';      
    unset($mail);


}
?>



 
 <html>
<head>
  <title>Contact Form</title>
</head>
<body>
                    
        <div style="margin: 100px auto 0;width: 300px;">
            <h3>Contact Form</h3>
            <form name="form1" id="form1" action="" method="post">
                    <fieldset>
                      <input type="text" name="fullname" placeholder="Full Name" />
                      <br />
                      <input type="text" name="subject" placeholder="Subject" />
                      <br />
                      <input type="text" name="phone" placeholder="Phone" />
                      <br />
                      <input type="text" name="emailid" placeholder="Email" />
                      <br />
                      
                      
                     <input type="file" name="attachment" id="attachment" >
                      <br />  
                      
                      <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea>
                      <br />
                      <input type="submit" name="submit" value="Send" />
                    </fieldset>
            </form>
            <p><?php if(!empty($message)) echo $message; ?></p>
        </div>
                    
</body>
</html>

</div>
  • 写回答

1条回答 默认 最新

  • duanleiliu7373 2017-06-21 12:55
    关注

    <?php
    
    if(isset($_POST['submit'])) 
    {
    $attachment = $_FILES['attachment']['tmp_name'];
    $attachment_name = $_FILES['attachment']['name'];
    $message=
    'Full Name: '.$_POST['fullname'].'<br />
    Subject:    '.$_POST['subject'].'<br />
    Phone:  '.$_POST['phone'].'<br />
    Email:  '.$_POST['emailid'].'<br />
    Attachment: '.$attachment.'<br />
    Comments:   '.$_POST['comments'].'
    ';
    
    
    require 'PHPMailer/PHPMailerAutoload.php';
    
    
    
    
    
    
    $mail = new PHPMailer;
    
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'lijojohn004@gmail.com';                 // SMTP username
    $mail->Password = '******';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to
    
    
    
    
    $mail->SetFrom($_POST['emailid'], $_POST['fullname']);
    $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
    $mail->Subject = "New Contact Form Enquiry";      // Subject (which isn't required)  
    $mail->MsgHTML($message);
    
    $mail->addAttachment($attachment,$attachment_name);         // Add attachments
    $mail->isHTML(true);   
     
     
     
    
        $mail->addAddress('lijomattathil@gmail.com', 'Website');     // Add a recipient
        $result = $mail->Send();     // Send!  
        $message = $result ? 'Successfully Sent!' : 'Sending Failed!';      
        unset($mail);
    
    
    }
    ?>
    
    
    
     
     <html>
    <head>
      <title>Contact Form</title>
    </head>
    <body>
                        
            <div style="margin: 100px auto 0;width: 300px;">
                <h3>Contact Form</h3>
                <form name="form1" id="form1" action="" method="post" enctype="multipart/form-data">
                        <fieldset>
                          <input type="text" name="fullname" placeholder="Full Name" />
                          <br />
                          <input type="text" name="subject" placeholder="Subject" />
                          <br />
                          <input type="text" name="phone" placeholder="Phone" />
                          <br />
                          <input type="text" name="emailid" placeholder="Email" />
                          <br />
                          
                          
                         <input type="file" name="attachment" id="attachment" >
                          <br />  
                          
                          <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea>
                          <br />
                          <input type="submit" name="submit" value="Send" />
                        </fieldset>
                </form>
                <p><?php if(!empty($message)) echo $message; ?></p>
            </div>
                        
    </body>
    </html>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度