473,378 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

PHP email is truncated

Hi,

I work at a newspaper.

I'm attempting to use the PHP mail function to send a computer generated message to an email list. The email message contains html, text and photos. Its the major headlines and pictures from the day's current news.

The email message is getting truncated. The HTML displays fine in a browser.

I've checked the HTML syntax. But I'm only sending half the message. No error messages are returned.

Mike
Mar 20 '07 #1
3 2293
ak1dnar
1,584 Expert 1GB
Hi Mike,
how do you planing to send HTML emails, is it a Remote web server or are you using our local machine's web server and PHP.
If it is a news paper day by day you have to change the headings and other elements. Is there any back end system to arrange those stuffs with out change the mail page manually.

And i need the script that you have completed so far.
Mar 21 '07 #2
I'm using a remote server.
Here's the script followed by the raw email content its generating.

<?php

/* CONNECT TO THE DB AND BUILD HASH OF EMAIL's*/

$root = $_SERVER[ROOT_CONTENT_FOLDER];

// Connect to email list db

$connection = mysql_connect('db.townnews.com', 'dinterlake', <?=$password?>) or die ('Unable to connect!');

mysql_select_db('dailyinterlake_com') or die ('Unable to select database');

$results = mysql_query("select * from cust_email_list WHERE avail = 'Y'");

while ($row = mysql_fetch_assoc($results))
{
foreach($row as $key=>$val)
{
if(preg_match("/email/", "$key"))
{
$email_list[] .= $val;
}
}
}


/* BEGIN MESSAGE TO SEND */

$site = "http://www.dailyinterlake.com/content/current";

$msg .= '<table width="80%"><tr><td>';

$msg .= '<h3>THE DAILY INTER LAKE NEWS ALERT</h3>
Bringing you the latest news from around the Flathead Valley<br/>
===============================================<br/><br/>';

/* BUILD CONTENT FOR EACH NEWS CATEGORY */

foreach(array('breaking_news','news','law_roundup' ,'sports', 'business','lifestyle', 'weather', 'traffic') as $folder)
{
$filenames = '';

$dir = $root . '/' . $folder;

/* OPEN CONTENT FOLDER ON SERVER */

if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if(preg_match("/([a-zA-Z0-9])+.txt/", $file)) // Don't save non-text files
{
$filenames[] .= $file; // Add to filenames array
}
else if(preg_match("/([a-zA-Z0-9])+.jpg/", $file)) // If photo is availble, add to hash with text file as key
{
$key = preg_replace("/.jpg/", '.txt', $file); // photo file name is same as corresponding text file
$photos[$key] = $file;
}

}
}

if(!$filenames) // couldn't find any for this news category
{
continue;
}

sort($filenames);


/* CREATE NEWS HEADING AND ADD TO MESSAGE */
$fldr = strtoupper($folder);

$msg .= "<h3>$fldr</h3>\n";


/* GET FILE CONTENTS FOR EACH FILE IN ARRAY */

foreach($filenames as $file)
{

$filename = $dir . '/' . $file;

if(file_exists("$filename"))
{

$handle = fopen($filename, "r");
$content = fread($handle, filesize($filename));
fclose($handle);

/* CLEANUP FILE CONTENTS */

$content = preg_replace("/ +/", ' ', $content); // compress whitespace
$content = preg_replace("/\n+/", "\n", $content); // remove blank lines
$content = preg_replace("/^ +/", '', $content); // remove leading whitespace
$content = preg_replace("/^\n+/", '', $content); // remove leading line feeds
$content = preg_replace("~^[bB]y ([^\n])+\n~", "By $1 ", $content); // Fix byline in content
$content = preg_replace("~^[bB]y ([^\n])+<br/?>~", "By $1 ", $content);

$parts = preg_split("/\n/", $content); // split content into lines

// initialize

$head = '';
$byline = '';
$kicker = '';
$teaser = '';


/* DETECT PRINCIPAL PARTS OF CONTENT (Heading, byline, kicker, teaser ) */

//Use XML tags if present

$p = 1;

foreach($parts as $part)
{
$sansxml = preg_replace("/<[^>]+>/", '', $part);

if(preg_match("/<!--head/", $part) && ($head == ''))
{
$head = $sansxml;
}
else if(preg_match("/<!--byline/", $part) && ($byline == ''))
{
$byline = $sansxml;
}
else if(preg_match("/<!--kicker/", $part) && ($kicker == ''))
{
$kicker = $sansxml;
}
else if(preg_match("/[a-zA-Z]/", $part) && ($teaser == '') && ($header != ''))
{
$teaser .= $sansxml;
}
else
{
}

if($p > 5) // Don't look at more than 5 lines
{
break;
}
}

// use position if no xml

$p = 1;

foreach($parts as $part)
{

if(!preg_match("/[a-zA-Z]/", $part))
{
continue;
}

if($byline == '' && preg_match("/^[Bb]y /", $part))
{

if(preg_match("/[dD]aily\s*[iI]nter\s*[lL]ake/", $part))
{
$byline = $part;
}
else if(preg_match("/[dD]aily\s*[iI]nter\s*[lL]ake/", $part[$p]))
{
$byline = $part;
$part[$p] = '';
}
}
else if($head == '')
{

$head = $part;
}
else if($teaser == '')
{

$teaser.= $part;

}

$p++;

if($p > 5) // Don't look at more than 5 lines
{
break;
}

}

/* ADD HEAD TO MESSAGE STRING */

$content = '<h2>' . $head . '</h2>' . "\n";


/* ADD CONTENT PARTS TO MESSAGE STRING */

if($photos[$file] != '') // Add photo if there
{
$pic = $photos[$file];
$content .= "<img src=\"$site/$folder/$pic\" width = '400px'><p>\n";
}

if($byline != '')
{
$content .= "<i><b>$byline</b></i><p>\n"; // Add byline to string
}

if($kicker != '')
{
$content .= "<b>$kicker</b><p>\n"; // Add kicker to string
}

if($teaser != '')
{
$content .= "<b>$teaser</b><p>\n"; // Add teaser to string
}


/* ADD MORE LINK TO STRING */

$more = "http://www.dailyinterlake.com/$folder/$file";

$content .= "<p><a href=\"$more\">Read More</a>\n";


/* ADD HORIZONTAL RULE TO SEPARATE NEWS SECTIONS */

$msg .= $content . '<P><hr></P>' . "\n";


}

}


}

/* END MESSAGE STRING */

$msg .= '</td></tr></table>' . "\n";


/* CREATE 'TO' STRING BY imploding ALL EMAIL ADDRESSES */

$to = implode(', ', $email_list);

// subject
$subject = 'Daily Inter Lake News Alert';

// To send HTML mail, the Content-type header must be set

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: News Alert <webmaster@dailyinterlake.com>' . "\r\n";

// Mail it

$mail_sent = mail($to, $subject, $msg, $headers) or die ('Unable to mail');;

?>

-------------------------------------------------------------------------------------------------
Here's the raw email source (minus the heading stuff)

<table width="80%"><tr><td><h3>THE DAILY INTER LAKE NEWS ALERT</h3>
Bringing you the latest news from around the Flathead Valley<br/>
===============================================<br/><br/><h3>NEWS</h3>
<h2>Spring cleaning</h2>
<img src="http://www.dailyinterlake.com/content/current/news/news01.jpg" width = '400px'><p>
<p><a href="http://www.dailyinterlake.com/news/news01.txt">Read More</a>
<P><hr></P>
<h2>Biologists pan subdivision rules</h2>
<i><b>By WILLIAM L. SPENCE<br>The Daily Inter Lake</b></i><p>
<b>Farmers also oppose proposals</b><p>
<p><a href="http://www.dailyinterlake.com/news/news02.txt">Read More</a>
<P><hr></P>
<h2>Counties may get funding increase</h2>
<i><b>By JIM MANN<br>The Daily Inter Lake</b></i><p>
<b>Montana counties would get substantially more money under a payment package announced Tuesday by Sen. Max Baucus, D-Mont. </b><p>
<p><a href="http://www.dailyinterlake.com/news/news03.txt">Read More</a>
<P><hr></P>
<h2>Whitefish stalls vote on control outside city</h2>
<i><b>By LYNNETTE HINTZE<br>The Daily Inter Lake</b></i><p>
<b>A proposal to give the city of Whitefish more control in its unincorporated planning area was put on hold Monday to allow time for county officials to address their concerns.</b><p>
<p><a href="http://www.dailyinterlake.com/news/news04.txt">Read More</a>
<P><hr></P>
<h2>Subdivision OK’d on Church Slough</h2>
<i><b>By JIM MANN<br>The Daily Inter Lake</b></i><p>
<b>Flathead County commissioners on Tuesday granted preliminary approval for a subdivision on Church Slough, with an agreement that paves the way for a public boat access.</b><p>
<p><a href="http://www.dailyinterlake.com/news/news05.txt">Read More</a>
<P><hr></P>
<h2>Whitefish, state blaze new deal for trails</h2>
<i><b>By LYNNETTE HINTZE<br>The Daily Inter Lake</b></i><p>
<b>A precedent-setting land-use license will allow the city of Whitefish to move forward with its Trail Runs Through It project without having to buy easements on state school trust land.</b><p>
<p><a href="http://www.dailyinterlake.com/news/news06.txt">Read More</a>
<P><hr></P>
<h2>Yea or neigh</h2>
<i><b>By JOHN STANG</b></i><p>
<b><!--byline-->By JOHN STANG</b><p>
<p><a href="http://www.dailyinterlake.com/news/news07.txt">Read More</a>
<P><hr></P>
<h3>LAW_ROUNDUP</h3>
<h2>A night of restless teens, assaults</h2>
<b>Reports of rowdy youths wreaking havoc keep Kalispell police busy Monday evening.</b><p>
<p><a href="http://www.dailyinterlake.com/law_roundup/law_roundup01.txt">Read More</a>
<P><hr></P>
<h2>Flathead County Sheriff</h2>
<b>He was extremely drunk when an ambulance brought him to the emergency room, and medical personnel didn’t want him to leave. He had other ideas, and since he couldn’t get a taxi, a Flathead County Sheriff’s deputy took him home to Bigfork.</b><p>
<p><a href="http://www.dailyinterlake.com/law_roundup/law_roundup02.txt">Read More</a>
<P><hr></P>
<h2>Columbia Falls police</h2>
<b>Columbia Falls police are investigating a report of a 12-year-old boy being assaulted on the bike path near the junior high school. He suffered cuts and broken bones.</b><p>
<p><a href="http://www.dailyinterlake.com/law_roundup/law_roundup03.txt">Read More</a>
<P><hr></P>
<h2>Whitefish ambulance</h2>
<b>A man who appeared to be in his mid-20s got sick and passed out at the Whitefish train depot. Whitefish ambulance took him to the hospital.</b><p>
<p><a href="http://www.dailyinterlake.com/law_roundup/law_roundup04.txt">Read More</a>
<P><hr></P>
<h3>SPORTS</h3>
<h2>Raising a ruck-us
Mar 21 '07 #3
Thanks all.

I found the problem.

Montana Gramps
Mar 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jay Chan | last post by:
The transaction log in a database in our SQLSERVER-2000 server has grown to 16GB. I cannot shrink the transaction log manually because it says that the entire 16GB log size is not free. This is...
8
by: Dave Smithz | last post by:
Hi, Thanks to this group I discovered the excellent PHP Mailer (http://phpmailer.sourceforge.net/) which I use to send emails. Part of my application emails out hundreds of club members unique...
0
by: nekiv90 | last post by:
Greetings, Can someone see what goes wrong with email notification from Health center? I'm running DB2 v8.2.2 on W2K. I am able to test connection to database successfully, confirm correct...
5
by: z. f. | last post by:
hi, i have a vb.net web application and i make a request using internet explorer to an aspx page. the aspx page size if over 170KB, and the page in internet explorer looks truncated and in the...
0
by: Andrew | last post by:
Hello, friend, We useed System.Net.Socket class to send email. However, the message body was truncated if its size was 1k or more. Any ideas? Thanks a lot.
0
by: David A. Schramm | last post by:
I am using OLE DB in .NET 2 to insert a row into an Access database. The source is a RTF control and the column is a Memo field. The data is being truncated along the way. The control's rtf...
7
Coldfire
by: Coldfire | last post by:
i am having error ....details are ASP.Net application...in which I have a textbox <asp:TextBox ID="Other" TextMode=SingleLine CssClass="serviceBox" Width="250" Height="45" Runat="server"...
0
by: RickVidallon | last post by:
Missing or Truncated Body Text in Email Application - 2 Strange Examples... There is no earthly reason why this is happening! EXAMPLES HERE: http://65.36.227.70/actmailer/ We have a...
0
by: data monkey | last post by:
My company's web application uses mySQL databases. I have linked these tables (Read only) into Access 2007 so I can create queries and reports. Now I need to extract some of the content from these...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.