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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 电脑拓展屏桌面被莫名遮挡
  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?