Grow your CSS skills. Land your dream job.

problem sending an attachment to email via php

  • # January 30, 2012 at 4:58 pm

    Hey everyone,
    I’m pretty new to this php stuff, but I’m trying to create a page that the user uploads there resume and that gets sent to my email account. Right now it says its been sent, but I don’t see it in my inbox at all. I don’t know what I’m doing wrong

    Can anyone look at the code and tell me what I’m doing wrong TIA
    here’s the link

    and my code:

    < ?php
    $name = $_POST;
    $email = $_POST;
    $eligible = $_POST;
    $type = $_POST;

    if(isset($_POST))
    {
    //The form has been submitted, prep a nice thank you message
    $output = "
    ";
    "

    Email Sent Successfully.

    ";
    "

    Thank you $name, your resume has been submitted to us.

    ";
    "
    ";


    //Set the form flag to no display (cheap way!)
    $flags = 'style="display:none;"';

    //Deal with the email
    $to = 'andre@cssto.com';
    $subject = 'Magic Bus Company Employment Application Form';

    // $message = strip_tags($_POST);
    $attachment = chunk_split(base64_encode(file_get_contents($_FILES)));
    $filename = $_FILES;

    $boundary =md5(date('r', time()));

    $headers = "From: $emailrnReply-To: $to";
    $headers .= "rnMIME-Version: 1.0rnContent-Type: multipart/mixed; boundary="_1_$boundary"";

    $message="This is a multi-part message in MIME format.
    Name: $name;rnn
    Email: $email;rnn
    Are you eligible to work in Canada? $eligible;rnn
    What type of drivers license do you have? $type;rnn

    --_1_$boundary
    Content-Type: multipart/alternative; boundary="_2_$boundary"

    --_2_$boundary
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    $message

    --_2_$boundary--
    --_1_$boundary
    Content-Type: application/octet-stream; name="$filename"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment

    $attachment
    --_1_$boundary--";

    mail($to, $subject, $message, $headers);
    }
    ?>
    < !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">









    < ?php echo $output; ?>

    >

































    # February 1, 2012 at 12:03 am

    I would put a condition on the mail() function and see what it returns.

    I think your error/success messages should really be moved down the code so they are dependent on the mail function succeeding rather than just the posting of the form itself.

    if (mail($to, $subject, $body, $headers)) {
    echo(“Thank you for your submission.”);
    }
    else {
    echo(“We’re sorry, but there was an error processing your request.”);
    }

    This should point you as to whether your PHP system is actually sending the mail at all. I have had problems with the basic mail() function on certain ISP.

    # February 1, 2012 at 4:30 pm

    Thank a lot I’ll give it a try and let you know :)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".