Patricia Moore
Patricia Moore

Reputation: 53

How to attach a video file and email it using phpmailer?

I am making use of phpmailer to email my form details, it has a name field and a fil upload field and want to attach the name and video and email it using phpmailer, here is the sample code that i have used.

html form

    <form action='<?php bloginfo('template_directory'); ?>/upload.php' method='post' enctype="multipart/form-data">
          <div class="col-md-12">
            <div class="inner-addon left-addon col-md-3 col-sm-12 col-xs-12" style="display : inline-block">
              <i class="glyphicon glyphicon-user"></i>
              <input type="text" name="name" placeholder="Full Name" class="form-control"style="padding-left: 35px;font-size: 14px;" required/>
            </div>
            <div class="col-md-12" style="padding : 0px !important">
         <div class="inner-addon left-addon col-md-3 col-sm-12 col-xs-12" style="display : inline-block; padding:0px !imporant;" >
         <div class="col-md-8 col-sm-8 col-xs-8" style="padding:0px;">
          <input id="uploadFile" class="form-control" placeholder="Choose File" disabled="disabled" style="border-radius: 4px 0px 0px 4px; background-color: #fff;"/></div>
          <div class="col-md-4 col-sm-4 col-xs-4" style="padding:0px !important"><div class="fileUpload btn btn-primary" style="margin:0px !important; height:45px;width:100%; border-radius: 0px 4px 4px 0px; background-color:#9177ad; border : 1px solid #9177ad;">
            <span style="line-height: 2.428571;">Upload</span>
            <input id="uploadBtn" name="fileToUpload" type="file" class="upload" required />
          </div></div>
          </form>    

upload.php

<?php

    require __DIR__ . '/PHPMailer/PHPMailerAutoload.php';
    $name = $_POST["name"];
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.mandrillapp.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;
    $mail->setFrom('email', 'email');
    $mail->addAddress('[email protected]', 'name');     // Add a recipient
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $name;
    $mail->Body    = 'hi';
    if (isset($_FILES['fileToUpload']) &&
        $_FILES['fileToUpload']['error'] == UPLOAD_ERR_OK) {
            $mail->AddAttachment($_FILES['fileToUpload']['tmp_name'],
                                 $_FILES['fileToUpload']['name']);
    }            
    if(!$mail->send()) {
          error_log('Message could not be sent.');
          error_log('Mailer Error: ' . $mail->ErrorInfo);
        } else {
          error_log('Message has been sent');
    }  

but the problem is i am not able to attach the video from my desktop, but whereas it is working fine with image and document files. I tried to echo the file type for video and it returned nothing. so can some one help me out with this. I tried to echo the file type for video and it returned nothing.

Upvotes: 2

Views: 1614

Answers (1)

cantelope
cantelope

Reputation: 1165

In your php.ini file, verify that the following is set:

memory_limit = 40M
post_max_size = 40M
upload_max_filesize = 40M
file_uploads = On

Upvotes: 1

Related Questions