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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:22:40+00:00 2026-05-26T22:22:40+00:00

I am trying to make a script to send emails and attach pdfs or

  • 0

I am trying to make a script to send emails and attach pdfs or other types of files later on.

I have been following various tutorials and have come to a dead end.

Can anyone see anything wrong with my code? I think i have just been looking at it for far too long.

<?php
    include ("../../includes/auth.php");

    $id = $_GET['id'];
    $date = date('y-m-d h:i:s');

    $recipient = $_GET['email'];
    $lname = $_GET['lname'];
    $fname = $_GET['fname'];
    $subject ="Enquiry Form - $date";
    //-------------attachment stuff----------
    $fileatt = "/test.pdf";
    $fileatttype = "application/pdf";
    //$fileattname = "newname.pdf";
    $file = fopen($fileatt, 'rb');
    $data = fread($file, filesize($fileatt));
    fclose($file);
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    //-------------------------------------
    $headers = "From: test person <info@test.co.uk>";
    $headers .= "\nMIME-Version: 1.0\n".
    "Content-Type: multipart/mixed;\n".
    " boundary=\"{$mime_boundary}\"";
    $message = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n".
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n".
    "Content-Transfer-Encoding: 7bit\n\n". $message ."\n\n";
    $data = chunk_split(base64_encode($data));
    $message .= "–-{$mime_boundary}\n" .
    "Content-Type: {$fileatttype};\n" .
    " name=\"{$fileattname}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$fileatt}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n" ."--{$mime_boundary}--\n";
    $message ."Dear ".$fname." ".$lname." Test message".$date;

    echo $recipient."<br />";
    echo $subject."<br />";
    echo $message."<br />";
    echo $headers."<br />";

    mail($recipient, $subject, $message, $headers);

    include ("../../includes/dbconn.php");

    $set_datesent = "UPDATE _leads SET `Covering_letter_sent` = '$date' WHERE `ID` = '$id'";
    //echo $set_datesent;
    $result = mysql_query ($set_datesent, $connection)
    or die ("Failed to perform query :  $sql <br />".mysql_error());
?>
  • 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-05-26T22:22:41+00:00Added an answer on May 26, 2026 at 10:22 pm

    I would suggest you use something like the PEAR Mail library. Then sending an attachment becomes as easy and readable as the code below. You’ll have to make sure the Mail library is installed, but this is a fairly simple task.

    require_once('Mail.php');
    require_once('Mail/mime.php');
    
    $text = wordwrap($message, 70); // You'd put the text version of your message here as $message
    
    $mime = new Mail_Mime();
    $mime->setTXTBody($text);
    $mime->setFrom($name . ' <' . $from_email . '>'); // The sender name and email ID go here
    $mime->addAttachment($fpath, $ftype); // File path and type go here
    $mime->setSubject($subject); // Subject goes here
    
    $body = $mime->get()
    $headers = $mime->headers();
    
    $mail =& Mail::factory('mail');
    $mail->send($to_email, $headers, $body); // The recipients email address goes here
    
    unset($mime, $mail);
    

    Additional things also become much easier this way, for example, writing a HTML mail.

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

Sidebar

Related Questions

I have been trying to make an init script using start-stop-daemon. I am stuck
I have been figuring about and trying to make my IRC bot send private
I have spent the whole day trying to make a script which on submit
I'm trying to make a PHP script, I have the script finished but it
I am trying to make a Postgres PHP backup script. I have downloaded one
I trying to make a tell a friend script. The script must send an
Have been struggling all day trying to make this simple example work using socket.io.
I'm trying to make a script that automatically starts uploading after the data has
I'm trying to make a script that will go into a directory and run
I am trying to make a simple script to automate and log synchronization via

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.