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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:50:44+00:00 2026-06-04T22:50:44+00:00

I have been using this script to send emails to certain staff but because

  • 0

I have been using this script to send emails to certain staff but because of changes to my system i have to now send attachements with the email and i have tried multipul peices of code to accomplish this but have been unsuccessful… I still recive the email but without the attachement which is quite pointless in this case i have placed the script i am using bellow

i have removed the real addresses i was using and smtp server

    require("PHPMailer/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();    // set mailer to use SMTP
$mail->Host = "SMTP.SErver.com";    

$mail->From = "From@email.com";    
$mail->FromName = "HCSC";  
$mail->AddAddress("To@email.com", "Example"); 
$mail->AddReplyTo("Reply@email.com", "Hcsc"); 

$mail->WordWrap = 50;    
$mail->IsHTML(false);    

$mail->Subject = "AuthSMTP Test";
$mail->Body    = "AuthSMTP Test Message!";
$mail->AddAttachment("matt.txt"); //this is basicly what i am trying to attach as a test but will be using excel spreadsheets in the production

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

i have also tried a few other emtods of attaching the file but none seem to work any help is greatly appricated

  • 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-04T22:50:46+00:00Added an answer on June 4, 2026 at 10:50 pm

    Your code looks fairly straightforward and syntactically correct. Is the script returning any error messages?

    If you’re receiving the message without any issues, then the problem doesn’t look to be in your code.

    A few things to check:

    • Make sure that the file “matt.txt” is both readable by your webserver and that the path is correct. The path to the file needs to be included in the $mail->AddAttachment() method call and should be relative to the script’s location.
    • Verify that your mail server isn’t stripping any attachments out due to restrictions and/or try sending a different attachment file type (try a .zip or a .jpg file)
    • If you’re running a newer version of phpMailer, you can try catching any exceptions that are thrown (perhaps one that isn’t preventing the message from going out, but just preventing the attachment from being included) using the following syntax: (taken from phpMailer Example Code)

      require 'PHPMailer/PHPMailerAutoload.php';
      $mail = new PHPMailer(true);
      try {
      
        $mail->IsSMTP();    // set mailer to use SMTP
        $mail->Host = "SMTP.SErver.com";    
      
        $mail->From = "From@email.com";    
        $mail->FromName = "HCSC";  
        $mail->AddAddress("To@email.com", "Example"); 
        $mail->AddReplyTo("Reply@email.com", "Hcsc"); 
      
        $mail->WordWrap = 50;    
        $mail->IsHTML(false);    
      
        $mail->Subject = "AuthSMTP Test";
        $mail->Body    = "AuthSMTP Test Message!";
        $mail->AddAttachment("matt.txt");
        echo "Message Sent OK<p></p>\n";
      
      } catch (phpmailerException $e) {
      
        echo $e->errorMessage(); //Pretty error messages from PHPMailer
      
      } catch (Exception $e) {
      
        echo $e->getMessage(); //Boring error messages from anything else!
      
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using this as a reference, but not able to accomplish exactly
I have been using this so far system 'strings binary-file.dmp | grep search_string' Is
I have been using Perl for some time, but today I came across this
I have been using addslahes() . But this escapes database characters. However I need
Ok, I have been using the following script for over a year now to
I have been using a shopping cart script for a few years now and
I have been using this code with great success to pull out the first
I have been using this copy method for quite a while, in lots of
I have been using this excellent decorator for memoization, which I found on the
[i meant to ask this question on StackOverflow...] I have been using VisualSVN Server

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.