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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:32+00:00 2026-05-28T03:05:32+00:00

I am currently using a script which uses file_get_contents to get the contents of

  • 0

I am currently using a script which uses file_get_contents to get the contents of a php file, and then sends it inside an email to a list of customers. I would like to alter the script to allow for plain-text fallback to reduce the risk of being marked as spam.

This is the script I have at the moment:

    function sendit($to,$subject,$body)
{
$headers    =   "To: <{$to}>\n".
                    "From: Test Newsletter Admin <newsletter@test.co.uk>\n".
                    "Reply-To: Test Newsletter Admin <newsletter@test.co.uk>\n".
                    "MIME-Version: 1.0\n".
                    "Content-Type: text/html; charset=ISO-8859-1\n";

    $mail_sent = @mail($to, $subject, $body, $headers);
    return $mail_sent;
}
$content = file_get_contents('attach/newsletter.php');
//require_once('../../func.php');
set_time_limit(0);
date_default_timezone_set('Europe/London');

$log = fopen('send'.date('dmY',time()).'.log','wb');

//$array = file('NonCustClean.txt');
$array = file('devaddresses.txt');
// Delay In Seconds between emails (must be INT)
$delay = 10;
$count = count($array);

$end = time()+ ($delay*$count);

echo "Start Time: ".date('d/m/Y H:i:s',time()).'<br />';
echo "Estimated End Time: ".date('d/m/Y H:i:s',$end).'<br />';
echo "(".dateDiff(time(),$end).")<br />"; 

foreach ($array as $email)
 {

$status = (sendit(trim($email), 'Test Newsletter',$content))?'Sent':'failed';
 fwrite($log,date('[d/m/Y H:i:s]',time()).' Email '.$status.' to '.trim($email)."\n");
 echo date('[d/m/Y H:i:s]',time()).' Email '.$status.' to '.trim($email)."</br>";
 flush(); 
  sleep(10);
 }

Newsletter.php just contains basic HTML/CSS code.

Could someone please advise how I can alter this script to accompany a plain-text fallback?

Thanks for any help.

  • 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-28T03:05:33+00:00Added an answer on May 28, 2026 at 3:05 am

    What you’re looking for is known as a multipart e-mail. It’s body contains both HTML and text, delimited by a so called “boundary”. The e-mail client will then determine itself if it will show the HTML or Text version of the mail, based on it’s capabilities and user preferences.

    An example on how you can set this up (source):

    $notice_text = "This is a multi-part message in MIME format.";
    $plain_text = "This is a plain text email.\r\nIt is very cool.";
    $html_text = "<html><body>This is an <b style='color:purple'>HTML</b>" .
                 "text email.\r\nIt is very cool.</body></html>";
    
    $semi_rand = md5(time());
    $mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
    $mime_boundary_header = chr(34) . $mime_boundary . chr(34);
    
    $to = "Me <me@me.com>";
    $bcc = "You <you@you.com>, Them <them@them.com>";
    $from = "Me.com <me@me.com>";
    $subject = "My Email";
    
    $body = "$notice_text
    
    --$mime_boundary
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    
    $plain_text
    
    --$mime_boundary
    Content-Type: text/html; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    
    $html_text
    
    --$mime_boundary--";
    
    if (@mail($to, $subject, $body, 
        "From: " . $from . "\n" . 
        "bcc: " . $bcc . "\n" . 
        "MIME-Version: 1.0\n" . 
        "Content-Type: multipart/alternative;\n" . 
        "     boundary=" . $mime_boundary_header))
        echo "Email sent successfully.";
    else
        echo "Email NOT sent successfully!";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using some configuration files from several project modules inside batch script(scriptx.sh) which
I'm using emacs and I have written a script which uses current-buffer. However the
Right now, I have a script which uses PHP's tokenizer to look for certain
I am currently using Net::HTTP in a Ruby script to post files to a
I'm currently using the toprettyxml() function of the xml.dom module in a Python script
I am using Perl readdir to get file listing, however, the directory contains more
I have this code, which uses ob_start php function. Which basically puts the echoed
I have a ant build script that uses a build.properties file. There I have
Quick question; I replaced a .css file which I was referencing in html/php that
I am currently using generators as a quick way to get the progress of

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.