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

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
    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>
    
    点赞 评论

相关推荐