Results 1 to 8 of 8

Thread: PHP email help

  1. #1
    Join Date
    Feb 2007
    Location
    Colorado, USA
    Posts
    3,716
    Mentioned
    51 Post(s)
    Quoted
    624 Post(s)

    Default PHP email help

    So I can't use PEAR library because bad server is bad, anyways..
    I have a contact us setup for this company they also wanted a job application up there, with most of the same stuff as the contact us except they also want a place to attach something such as a resume to the email

    I figure something like browse to the file select it

    the server takes the file when it uploads to the temp directory and it attaches it to the email and then would send the email, (and then the temp directory auto deletes the uploaded file like normal)

    not sure how I would go about grabbing the temp file and attaching it to an email in PHP, I have found some different codes but they seem to require PEAR library (which I have on my server, but their host doesn't have...)


    Greatly appreciated
    The only true authority stems from knowledge, not from position.

    You can contact me via matrix protocol: @grats:grats.win or you can email me at the same domain, any user/email address.

  2. #2
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I always used http://swiftmailer.org/, but I am not sure if that helps you.
    Working on: Tithe Farmer

  3. #3
    Join Date
    Feb 2007
    Location
    Colorado, USA
    Posts
    3,716
    Mentioned
    51 Post(s)
    Quoted
    624 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    I always used http://swiftmailer.org/, but I am not sure if that helps you.
    Thanks but looks like it requires PEAR(which is the main email library for PHP) someone around here probably knows a quick piece of code that just grabs temp file and attaches to email, looking at upload code I've done before it will probably be like 5-10 lines of code only, I just have no idea how to attach to an email lol
    The only true authority stems from knowledge, not from position.

    You can contact me via matrix protocol: @grats:grats.win or you can email me at the same domain, any user/email address.

  4. #4
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Wrote this for you

    PHP Code:
    <?php

    /*
        Edit your variables here.
    */
    $filePath "/path/to/my/file/";
    $fileName "uploadedFile.doc";
    $emailFrom "someone@example.com";
    $emailTo "anybody@another.com";
    $emailSubject "Email with attachment!";
    $emailMessage "Open the attachment you mortal!";
    $emailCharset "utf-8";

    /*
        Don't touch here.
    */
    $fileInfoHandle finfo_open(FILEINFO_MIME_TYPE);
    $fileType finfo_file($fileInfoHandle$filePath.$fileName);
    finfo_close($fileInfoHandle);
    $fileData chunk_split(base64_encode(file_get_contents($filePath.$fileName)));
    $mimeBoundary "==Multipart_Boundary_x".md5(time())."x";

    $emailHeader "From: ".$emailFrom.PHP_EOL;
    $emailHeader .= "MIME-Version: 1.0".PHP_EOL;
    $emailHeader .= "Content-Type: multipart/mixed; boundary=\"".$mimeBoundary."\"".PHP_EOL;

    $emailRealMessage "This is a multi-part message in MIME format.".PHP_EOL.PHP_EOL;
    $emailRealMessage .= "--".$mimeBoundary.PHP_EOL;
    $emailRealMessage .= "Content-Type: text/html; charset=\"".$emailCharset."\"".PHP_EOL;
    $emailRealMessage .= "Content-Transfer-Encoding: 7bit".PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL;
    $emailRealMessage .= $emailMessage.PHP_EOL.PHP_EOL;
    $emailRealMessage .= "--".$mimeBoundary.PHP_EOL;
    $emailRealMessage .= "Content-Type: ".$fileType."; name=\"".$fileName."\"".PHP_EOL;
    $emailRealMessage .= "Content-Transfer-Encoding: base64".PHP_EOL.PHP_EOL;
    $emailRealMessage .= $fileData.PHP_EOL.PHP_EOL;
    $emailRealMessage .= "--".$mimeBoundary."--".PHP_EOL;

    $mailSent mail($emailTo$emailSubject$emailRealMessage$emailHeader);

    /*
        Ok, you can touch again.
    */
    if ($mailSent) {
        echo 
    "Congratulations! You've sent an email!";
    } else {
        echo 
    "Oops! Something went wrong.";
    }

    ?>
    EDIT: Sec
    EDIT2: Ok, bug fixed.
    Last edited by Frement; 05-10-2012 at 02:39 PM.
    There used to be something meaningful here.

  5. #5
    Join Date
    Feb 2007
    Location
    Colorado, USA
    Posts
    3,716
    Mentioned
    51 Post(s)
    Quoted
    624 Post(s)

    Default

    For example:
    http://www.w3schools.com/php/php_file_upload.asp

    When they upload the files it goes into a temp directory
    would we use something like $_FILES["file"]["tmp_name"] to pull from that temp directory and attach to the email? that's another part where I'm confused, going to try it out now that I'm not busy
    The only true authority stems from knowledge, not from position.

    You can contact me via matrix protocol: @grats:grats.win or you can email me at the same domain, any user/email address.

  6. #6
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    You can use move_uploaded_file() to copy the file to your temp directory (if you want to keep the file for a while.

    Then after sending the email, to delete the file, use this: unlink()
    There used to be something meaningful here.

  7. #7
    Join Date
    Feb 2007
    Location
    Colorado, USA
    Posts
    3,716
    Mentioned
    51 Post(s)
    Quoted
    624 Post(s)

    Default

    Well it is automatically deleted unless it's moved from the temp file, so I figured it could be added to the email and sent and then it would just do its usual auto deletion

    talking to one of the CEO's right now they're so beyond confusing I don't even know if they want this stuff anymore, but I'd still like to learn it

    uhg now the two guys are saying different shit, brb going to drive there real fast
    Last edited by grats; 05-10-2012 at 04:27 PM.
    The only true authority stems from knowledge, not from position.

    You can contact me via matrix protocol: @grats:grats.win or you can email me at the same domain, any user/email address.

  8. #8
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Well, anyway, theres everything you need Have fun coding!
    There used to be something meaningful here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •