dongyinting3179 2017-06-21 04: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 04: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>
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部