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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:27:29+00:00 2026-06-04T10:27:29+00:00

I am sending an email using PHP mail function, but I would like to

  • 0

I am sending an email using PHP mail function, but I would like to add a specified PDF file as a file attachment to the email. How would I do that?

Here is my current code:

$to = "me@myemail.com";
$subject = "My message subject";
$message = "Hello,\n\nThis is sending a text only email, but I would like to add a PDF attachment if possible.";
$from = "Jane Doe <janedoe@myemail.com>";

$headers = "From:" . $from; 
mail($to,$subject,$message,$headers);

echo "Mail Sent!";
  • 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-04T10:27:31+00:00Added an answer on June 4, 2026 at 10:27 am

    You should consider using a PHP mail library such as PHPMailer which would make the procedure to send mail much simpler and better.

    Here’s an example of how to use PHPMailer, it’s really simple!

    <?php
    
    require_once('../class.phpmailer.php');
    
    $mail             = new PHPMailer(); // defaults to using php "mail()"
    
    $body             = file_get_contents('contents.html');
    $body             = eregi_replace("[\]",'',$body);
    
    $mail->AddReplyTo("name@yourdomain.com","First Last");
    
    $mail->SetFrom('name@yourdomain.com', 'First Last');
    
    $mail->AddReplyTo("name@yourdomain.com","First Last");
    
    $address = "whoto@otherdomain.com";
    $mail->AddAddress($address, "John Doe");
    
    $mail->Subject    = "PHPMailer Test Subject via mail(), basic";
    
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    
    $mail->MsgHTML($body);
    
    $mail->AddAttachment("images/phpmailer.gif");      // attachment
    $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
    
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message sent!";
    }
    
    ?>
    

    An alternative to PHPMailer is http://swiftmailer.org/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have send an email using php mailer class. mail was sending successfully but
I am sending email newsletters using php mail() function. I have to track the
before few days i have been comfortably sending emails using PHP mail function. but
I've got a project where by I send email using PHP's inbuilt mail() function,
I'm having issues sending emails using the php mail() function. I know the php
I'm using the mail() function to test sending emails with image file attachments to
I have a problem when sending a form via email using the PHP Mail
I'm having a challenge with sending emails with arabic content using PHP's mail function.
I want to generate an email using the mail() function: <?php $to = 'nobody@example.com';
I just noticed that the email sent from my host using mail() function also

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.