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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:11:27+00:00 2026-06-10T00:11:27+00:00

I use the code to send email: <?php $to = someone@example.com; $subject = Test

  • 0

I use the code to send email:

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

But I got:

sendmail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory

And I don’t know how to add attachment and importantly I need to specify the Content-Type for attachment, can anyone help me?

Thanks!

  • 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-10T00:11:29+00:00Added an answer on June 10, 2026 at 12:11 am
    <?php 
    
    $to = "someone@example.com";
    $subject = "Test mail";
    $from = "someonelse@example.com <someonelse@example.com>";
    $message = "Hello! This is a simple email message.";
    
    // let's say you want to email a comma-separated-values
    $tofile = "col1,col2,col3\n";
    $tofile .= "val1,val1,val1\n";
    
    
    $filename  = "filename.csv";
    $random_hash = md5(date('r', time())); 
    $attachment = chunk_split(base64_encode($tofile)); 
    
    $headers = "From: " . $from . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"\r\n"; 
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-MSMail-Priority: Normal\r\n";    
    $headers .= "X-Mailer: PHP/" . phpversion();
    
    $body = "--PHP-mixed-".$random_hash."\r\n";
    $body .= "Content-Type: text/plain; charset=\"UTF-8\"\r\n";
    $body .= "Content-Transfer-Encoding: 8bit\r\n";
    $body .= $message;
    $body .= "\r\n\r\n";
    $body .= "\r\n--PHP-mixed-" . $random_hash . "\r\n\r\n";
    
    $body .= "--PHP-mixed-".$random_hash."\r\n";
    $body .= "Content-Transfer-Encoding: base64\r\n";
    $body .= "Content-Type: text/comma-separated-values; name=\"" . $filename . "\" charset=\"UTF-8\"\r\n"; 
    $body .= "Content-Disposition: attachment; filename=\"" . $filename . "\"\r\n\r\n";
    $body .= $attachment;
    $body .= "\r\n--PHP-mixed-".$random_hash."--";
    
    mail($to, $subject, $body, $headers);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use php default mail function to send html e-mails. My code: //SENDMAIL //
I`m trying to send e-mail via c# and use the following code: public static
I want to send an SMS via intent, but when I use this code,
I use the following code... $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP
I'm trying to use the Sending a basic message code from here to send
I have recently tried to use the php mail function to send out confirmation
I'm trying to use BCC fields in some PHP email. My code is as
Here is the javascript code I use to create the array and send it
Whenever I use the following code, the webserver (running IIS 7) refuses to send
Why cant i use code nuggets to set a control property??For example a validationgroup

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.