Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:47:51+00:00 2026-06-17T10:47:51+00:00

I am fairly new to php, and am unfamiliar with email headers. This is

  • 0

I am fairly new to php, and am unfamiliar with email headers. This is a function based on some code I came across / updated to use a file object. The result is a ‘File Sent Successfully gets echoed, but the email never comes. I can only assume this has something to do with the email headers that this thing is generating. Hopefully somebody see’s what’s wrong here:

function mail_attachment ($from , $to, $subject, $message, $attachment){ 
    $fileatt = $attachment["tmp_name"];
    $fileatt_type = "application/octet-stream";
    $fileatt_name = $attachment["name"]; 
    $email_from = $from;
    $subject = "New Attachment Message"; 
    $email_subject = $subject;
    $email_to = $to;
    $headers = "From: ".$email_from;   
    $file = fopen($fileatt,'rb'); 
    $data = fread($file,filesize($fileatt)); 
    fclose($file);
    $semi_rand = md5(time()); 
    $mime_boundary = "Multipart_Boundary_x{$semi_rand}x"; 
    $headers .= "\nMIME-Version: 1.0\n" . 
                "Content-Type: multipart/mixed;\n" . 
                "boundary=\"{$mime_boundary}\"";
    $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . 
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
                "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
    $data = chunk_split(base64_encode($data)); 
    $email_message .= "--{$mime_boundary}\n" . 
                "Content-Type: {$fileatt_type};\n" . 
                "name=\"{$fileatt_name}\"\n" . 
                "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" 
                . "--{$mime_boundary}--\n";   
    $ok = mail($email_to, $email_subject, $email_message, $headers);   
    if($ok) { echo "File Sent Successfully.";} 
    else { die("Sorry but the email could not be sent. Please go back and try again!"); } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:47:53+00:00Added an answer on June 17, 2026 at 10:47 am

    Use phpMailer()

    <?php 
    require_once('phpmailer.php');
    
    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
    $mail->IsSendmail(); // telling the class to use SendMail transport
    
    try {
        $mail->AddReplyTo('email@example.com', 'First Last');
        $mail->AddAddress('John@example.com', 'John Doe');
    
        $mail->SetFrom('email@example.com', 'First Last');
        $mail->Subject  =  "Subject Line";
        $mail->AltBody    = "Alternate Text"; // optional, comment out and test
    
        $mail->WordWrap     =   50; // set word wrap    
        $mail->Body = "This is the body of the email";
        $mail->IsHTML(true); // send as HTML
    
        // Single or Multiple File Attachments
        $mail->AddAttachment('../path-to-file.pdf', 'File-Name.pdf');
        $mail->Send(); // Try to send email
        //echo "Message Sent OK<p></p>\n";
        } catch (phpmailerException $e) {
            echo $e->errorMessage(); //Pretty error messages from PHPMailer
        } catch (Exception $e) {
            echo $e->getMessage(); //Boring error messages from anything else!
    }
    // end try
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to PHP and Codeigniter so im sure this will be
I'm fairly new to PHP, so I'm sorry if this is a dumb question.
I'm fairly new to PHP so am not sure how to do this. I
I am fairly new to PHP. I have a function which checks the cost
I've fairly new to PHP MVC and I'm not 100% sold I'm doing this
I'm fairly new to PHP and am looking for some best practices on how
I am fairly new with PHP and I'm stuck on this big time. I
I'm fairly new to php and I'm using a script that creates a function
i'm fairly new to PHP and can't seem to figure this one out. i've
Notes: I'm still fairly new to php This login form seems to work perfectly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.