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 8008183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:03:45+00:00 2026-06-04T18:03:45+00:00

I am using a class i found to email something with attachment, yet when

  • 0

I am using a class i found to email something with attachment, yet when i send the message it dosen’t appear. i’m trying to send an HTML message but even a regular one dosen’t send.
Can’t spot the error.
The email sends fine only the message is empty
Can someone take a look please?
Code:

<?php

class mailer{
    var $email_to;
    var $email_subject;
    var $headers;
    var $mime_boundary;
    var $email_message;

    //sets up variables and mail email
    function mailer($email_to,$email_subject,$email_message,$headers){
        $this->email_to=$email_to;
        $this->email_subject=$email_subject;
        $this->headers = $headers;
        $semi_rand = md5(time());
        $this->mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
        $this->headers .= "\nMIME-Version: 1.0\n" .
                "Content-Type: multipart/mixed;\n" .
                " boundary=\"{$this->mime_boundary}\"";
        $this->email_message .= "This is a multi-part message in MIME format.\n\n" .
                "--{$this->mime_boundary}\n" .
                "Content-Type:text/html; charset=\"iso-8859-1\"\n".
                $email_message . "\n\n";
    }

    //adds attachment
    function attach($fileatt_type,$fileatt_name,$fileatt_content){
        $data = chunk_split(base64_encode($fileatt_content));
        $this->email_message .= "--{$this->mime_boundary}\n" .
        "Content-Type: {$fileatt_type};\n" .
        " name=\"{$fileatt_name}\"\n" .
        "Content-Transfer-Encoding: base64\n\n" .
        $data . "\n\n" .
        "--{$this->mime_boundary}\n";
        unset($data);
        unset($file);
        unset($fileatt);
        unset($fileatt_type);
        unset($fileatt_name);
    }

    //send email
    function send(){
        return mail($this->email_to, $this->email_subject, $this->email_message, $this->headers);
    }



    //extra functions to make life easier

    //send email with imap
    function imap_send(){
        return imap_mail($this->email_to, $this->email_subject, $this->email_message, $this->headers);
    }

    //read file and add as attachment
    function file($file){
        $o=fopen($file,"rb");
        $content=fread($o,filesize($file));
        fclose($o);
        $name=basename($file);
        $type="application/octet-stream";
        $this->attach($type,$name,$content);
    }

    //read directory and add files as attachments
    function dir($dir){
        $o=opendir($dir);
        while(($file=readdir($o)) !==false){
            if($file != "." && $file != ".."){
                if(is_dir($dir."/".$file)){
                    $this->dir($dir."/".$file);
                }else{
                    $this->file($dir."/".$file);
                }
            }
        }
    }
}

message populate:

    $message  = "<span style='color:red;'>NOTICE: test tesx..";
 $message .= "test text";
 $message .= "Please text test.</span>";
 $message .= "If you encounter any problems please contact at contact@shibby.co.il";

calling the class:

      $mailer=new mailer($mail_to,$subject,$message,"From: $from_mail");
$mailer->file($fileName);

$test=$mailer->send();
  • 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-04T18:03:46+00:00Added an answer on June 4, 2026 at 6:03 pm

    For sending mail with attachment.

    <?php
    
    //If there is no error, send the email
    if(isset($_POST['ur_submit_button_name'])) {
    $uname=$_POST['uname'];
    $to = $_POST['mailid'];
    $mobileno=$_POST['mobile'];
    $location=$_POST['location'];
    $from = "Yourname <Yourname@domainname.com>";
    $subject = "This is the subject";
    
    $separator = md5(time());
    
    // carriage return type (we use a PHP end of line constant)
    $eol = PHP_EOL;
    
    // attachment name
    $filename = "ip.zip";//store that zip file in ur root directory
    $attachment = chunk_split(base64_encode(file_get_contents('ip.zip')));
    
    // main header
    $headers  = "From: ".$from.$eol;
    $headers .= "MIME-Version: 1.0".$eol; 
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
    
    // no more headers after this, we start the body! //
    
    $body = "--".$separator.$eol;
    $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
    $body .= "This is a MIME encoded message.".$eol;
    
    // message
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
    $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
    $body .= $message.$eol;
    
    // attachment
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
    $body .= "Content-Transfer-Encoding: base64".$eol;
    $body .= "Content-Disposition: attachment".$eol.$eol;
    $body .= $attachment.$eol;
    $body .= "--".$separator."--";
    
    // send message
    if (mail($to, $subject, $body, $headers)) {
    $mail_sent=true;
    echo "mail sent";
    } else {
    $mail_sent=false;
    echo "Error,Mail not sent";
    
    }
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using mail class to send email with attachment as image to multiple
I'm using the EmailMultiAlternatives class to send text and html mails with django. While
I know basics of UML and java's OO interpretations using class diagrams. But after
I'm using the JavaMail API that's been ported for Android found here but I
Trying to get this form to validate email using the function the professor said
I'm using ActionMailer to send emails, but I'd like to use Sinatra's Tilt rendering.
I'm trying to send emails from CakePHP but without success. I'm trying with CakeEmail
I am trying to test a sinatra app using minitest and capybara but get
Using the MailMessage class in .NET 4, I found an issue today that I'm
Using class name I am firing a click event in jquery. Class names are

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.