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

  • SEARCH
  • Home
  • 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 9192715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:59:32+00:00 2026-06-17T20:59:32+00:00

As I said in the title I need a little help with sending email

  • 0

As I said in the title I need a little help with sending email
The problem is that the attachments is not sending.
Here is the code I used…

Part 1 of the code:

<?php    
if(isset($_POST['action'] ) ){    
$action=$_POST['action'];    
$message=$_POST['message'];    
$emaillist=$_POST['emaillist'];    
$from=$_POST['from'];    
$replyto=$_POST['replyto'];    
$subject=$_POST['subject'];    
$realname=$_POST['realname'];     
$file_name=$_POST['file'];    
$contenttype=$_POST['contenttype'];    
        $message = urlencode($message);    
        $message = ereg_replace("%5C%22", "%22", $message);    
        $message = urldecode($message);    
        $message = stripslashes($message);    
        $subject = stripslashes($subject);    
}    
   ?>

Part 2 of the code

<?    
 if ($action){    
        if (!$from && !$subject && !$message && !$emaillist){    
        print "Please complete all fields before sending your message.";    
        exit;    
    }    
    $allemails = split("\n", $emaillist);    
            $numemails = count($allemails);      
          for($x=0; $x<$numemails; $x++){    
                $to = $allemails[$x];    
                if ($to){    
                $to = ereg_replace(" ", "", $to);    
                $message = ereg_replace("&email&", $to, $message);    
                $subject = ereg_replace("&email&", $to, $subject);    
                print "Sending mail to $to.......";    
                flush();    
                $header = "From: $realname <$from>\r\nReply-To: $replyto\r\n";    
                $header .= "MIME-Version: 1.0\r\n";    
                $header .= "Content-Type: text/$contenttype\r\n";    
                $header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";    
                $header .= "$message\r\n";    
                mail($to, $subject, "", $header);    
                print "Done<br>";    
                flush();    
               }    
               }    
}    
?> 

I think the problem is from “content type”.

  • 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-17T20:59:34+00:00Added an answer on June 17, 2026 at 8:59 pm

    For file you has to use the $_file
    Try to use following code its working fine

     $from = $email;
        $subject = "Contact Form ";
        $h = "From: $from\r\n";
        $uid = md5(date('r', time()));
        $to = 'abc@abc.com';
    
    
    
        if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == 0) {
            $fileatt = $_FILES['attachment']['type'];
            $ext = strrchr($fileatt, '.');
            $ftype = "";
            if ($ext == ".doc")
                $ftype = "application/msword";
            if ($ext == ".jpg")
                $ftype = "image/jpeg";
            if ($ext == ".gif")
                $ftype = "image/gif";
            if ($ext == ".zip")
                $ftype = "application/zip";
            if ($ext == ".pdf")
                $ftype = "application/pdf";
            if ($ftype == "")
                $ftype = "application/octet-stream";
            $content = chunk_split(base64_encode(file_get_contents($_FILES['attachment']['tmp_name'])));
            $filename = $_FILES['attachment']['name'];
        } else {
            $fileatt = '';
            $ftype = "";
            $content = '';
            $filename = '';
        }
        $h .= "Reply-To: " . $to . "\r\n";
        $h .= "MIME-Version: 1.0\r\n";
        $h .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n\r\n";
        $h .= "This is a multi-part message in MIME format.\r\n";
        $h .= "--" . $uid . "\r\n";
        $h .= "Content-type:text/html; charset=iso-8859-1\r\n";
        $h .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        $htmlMessage .= 'Name : ' . $name . '<br>';
        $htmlMessage .= 'Email :' . $email . '<br>';
        $htmlMessage .= 'Compnay Name :' . $companyname . '<br>';
    
        $h .= $htmlMessage . "\r\n\r\n";
        $h .= "--" . $uid . "\r\n";
        $h .= "Content-Type: " . $ftype . "; name=\"" . $filename . "\"\r\n";
        $h .= "Content-Transfer-Encoding: base64\r\n";
        $h .= "Content-Disposition: attachment; filename=\"" . $filename . "\"\r\n\r\n";
        $h .= $content . "\r\n\r\n";
        $h .= "--" . $uid . "--";
        mail($to, $subject, strip_tags($htmlMessage), str_replace("\r\n", "\n", $h));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title said, I need to raise (from the C# code behind a
As already said in the title, I need some help with converting lat/long to
As the title said: Is it possible to send an email (using php mail())
As said in the title, I have a scrollview that should be listening for
Somebody said that when your PHP code and application use global variables then it
As the title said i need a way to set the variable name depending
As the title said, I need to format a string of text in format
I have a problem that I need to solve. I create Youtube videos and
Like said on title, i need to get all the users assigned to a
Title said it all. Some context: I got a search mechanism - search view,

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.