Page 1 of 1

How to send file as an attachment with phpmailer

Posted: Sat Apr 25, 2009 3:37 am
by eshban
Hello

I am using PHPMAILER library to send email with attachment fro my website.

Actually there is a form on my website, and a browser button. User come onto my website and use the "browse" button to select from his PC. And fianlly press the submit button of the form. In that case i receive the email but not the complete attachment.

Is there any specific way to do you. I just want that whatever files user upload from that browse button I got that in my email with the attachement.

here is my code

Code: Select all

 
 
$mailcomp = & new PHPMailer();
        $mailcomp->From     = "aaa@aaa.com";
        $mailcomp->FromName = "Digitizing Art";//
        $mailcomp->Host     = "Digitizing Art";
        $mailcomp->Mailer   = "sendmail";
        $mailcomp->Sender = "aaa@aaa.com";      
        $mailcomp->Subject = "Digitizing Art Order Details";
        
         // HTML body
    $body  = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
    $body .= "<i>Your</i> personal photograph to this message.<p>";
    $body .= "Sincerely, <br>";
    $body .= "phpmailer List manager";
    
    // Plain text body (for mail clients that cannot read HTML)
    $text_body  = "Hello " . $row["full_name"] . ", \n\n";
    $text_body .= "Your personal photograph to this message.\n\n";
    $text_body .= "Sincerely, \n";
    $text_body .= "phpmailer List manager";
    
    $mailcomp->Body    = $body;
    $mailcomp->AltBody = $text_body;
    $mailcomp->AddAddress("aaa@aaa.com");
    $mailcomp->AddStringAttachment($_REQUEST["fileField1"], "YourPhoto.jpg");
        
if(!$mailcomp->Send())      
          echo "There has been a mail error sending" ;
 
    // Clear all addresses and attachments for next loop
        $mailcomp->ClearAddresses();
        $mailcomp->ClearAttachments();
 
Kindly help me that how can i fix that problem.

Thanks

Re: How to send file as an attachment with phpmailer

Posted: Sat Apr 25, 2009 6:01 am
by ullasvk
If you are using gmail as smtp server, i can help you, since i did this using gmail.

Re: How to send file as an attachment with phpmailer

Posted: Sat Apr 25, 2009 6:24 am
by eshban
i just need solution or code so that whatever user uploads from the browse button i will got an email as an attachment.
here is my application link

Code: Select all

http://eshban.com/demos/zahid/sendorder.php
plz help so that user will send me the files selected in browse button

thanks

Re: How to send file as an attachment with phpmailer

Posted: Sat Apr 25, 2009 4:43 pm
by McInfo
In place of

Code: Select all

$mailcomp->AddStringAttachment($_REQUEST["fileField1"], "YourPhoto.jpg");
try

Code: Select all

$mailcomp->AddAttachment($_FILES['fileField1']['tmp_name'], 'YourPhoto.jpg');
or

Code: Select all

$mailcomp->AddAttachment($_FILES['fileField1']['tmp_name'], $_FILES['fileField1']['name'], 'binary', $_FILES['fileField1']['type']);
I have not tested this.

PHPMailer Documentation: Using Attachments

Edit: This post was recovered from search engine cache.