randomly cut off emails

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

randomly cut off emails

Post by edweill »

I have recently set up a system for sending multi-part emails to clients from a complicated form set. The emails will always have both 'text/plain' and 'text/html' portions, and will sometimes have pdf file attachments. These emails will be sent to from 1 to 5 addresses in the 'to:' and from 0 to 5 addresses in 'CC'. There is also a confirmatory copy of only the 'text/plain' portion sent to our office.

In initial testing, everything looked good, but now that we have moved to beta testing, we are having a problem with apparently random emails being cut off. This results in blank email presentation in the html emails (they are usually cut off in the <head> before the <body>). Some of the 'text/plain' only ones are cut off also. Of the 9 sets of test emails sent yesterday (18 emails), 7 were cut off.

We are posting the emails through SMTP on localhost. I have verified that the html and plain text are properly configured before being fed to the Swift object.

Does anyone have any ideas about possible sources for this issue? Or even places to look and things to check?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Are you running this from a shared server using the disk cache with /tmp ? People have experienced issues with web hosts cleaning out /tmp periodically and therefore deleting the temporary cache files if you're using the disk cache. If that is the case you should simply change from /tmp to somewhere else. If you've not got a clue what I'm talking about then you won't be using the disk cache.

Please post some code so I can try to identify where the problem lies.
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

code

Post by edweill »

here it is:

validation provides $valid==true
$OUTPUT contains the text and html versions of the email
$totalsize is the calculated size of the attachements in Kb
$BROKER contains data about the user

Code: Select all

if ($valid == true){
//Create the message
$message =& new Swift_Message("Enrollment Forms and Benefit Summaries from Company");
 
//Add some "parts"
$message->attach(new Swift_Message_Part($OUTPUT['text']));
$message->attach(new Swift_Message_Part($OUTPUT['html'], "text/html"));
 
///********************************************** Setup files ********************************************/

if (isset($_POST['email_pdf'])&&($_POST['email_pdf']=='PDF')&&($totalsize<2000)){
	// attach the pdfs
	foreach($cst as $key=>$val){
		foreach($val as $tkey=>$tval){
			foreach($tval as $stkey=>$stval){
				if ($stval['pdf_Idx']==$PDF[$key][$stval['pdf_Idx']]){
					$fileatt = "/home/comany/public_html".$stval['url']; // Path to the file 
					$filenm = basename($stval['url']);
		$message->attach(new Swift_Message_Attachment(new Swift_File($fileatt), $filenm, "application/pdf"));
	
				}
			}
		}
	}	
}
//
//Now check if Swift actually sends it

if ($swift->send($message, $recipients, new Swift_Address("info@company.com", "Company Information"))){
	echo "Sent email to mailing list<hr>";
}else{ echo "Failed";}
 
	
	
	// next send the email to the proper store
	// add broker info
	$body = '
	real email = '.$OFFICE['email'].'
	
	Name      '.$BROKER['first_Name'].$BROKER['last_Name'].'
	Company   '.$BROKER['firm_Name'].'
	Address   '.$BROKER['address'].'
	City      '.$BROKER['city'].'
	State     '.$BROKER['state'].'
	Zip       '.$BROKER['zip'].'
	Phone     '.$BROKER['phone'].'
	Ext       '.$BROKER['phone2'].'
	Email     '.$BROKER['email'].'
	Group     '.$BROKER['group'].'
	Contact   '.$BROKER['contact'].'
	
	'.$OUTPUT['text'];
	//Start Swift
	$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
	 
	//Create the message
	$message =& new Swift_Message("Enrollment Forms and Benefit Summaries from LISI", $body);
	 
	//Now check if Swift actually sends it
	if ($swift->send($message, "bbolls@company.com", "info@company.com")){
		echo "Sent materials request to LISI";
	}else{
		echo "Failed";
	}
	 
}else{
	// invalid email addresses
echo '<h1> Invalid email addresses! </h1>
		';
	foreach ($messages as $val){
		echo $val.' <br>
		';
	}
echo '<strong> Please return to verify email and try again. </strong>
		';
}
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

using cache

Post by edweill »

I don't believe I am using the cache, and I am not reading the message from a file. I have generated it in the code and fed it into a variable which is used to load the mailer. Would setting it to use a local cache be of any benefit?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Using the cache won't actually change if this works or not, although it usually a good idea to turn it on if you can.

When you say "usually cut off in the <head>", are you viewing the source code of the email or is this just what you see in your mail client when trying to view the email normally? It sounds odd that Swift would terminate a message partway through the body since it just reads the variable. Have you debugged this by dumping the contents of $OUTPUT at all? How are you creating $OUTPUT? :)
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

cut off emails

Post by edweill »

I have tested the contentes of $OUTPUT. In the previous page of the system, $OUTPUT['email'] was displayed for approval by the user, then stored in the $_SESSION variable. I will set the emailing page to also display the $OUTPUT variables after the email to confirm that they were complete at the time of sending. -- This is a good idea -- thanks!

When I say usually cut off in the <head> I mean that if I view source on the recieved email, the message ends in the head. My spam blocker also complains about lack of closing tags in it's header messages.

$OUTPUT is being generated in the previous page of the system from output templates (one for html, one for plain text), displayed for approval in that page, and stored in $_SESSION to carry it into the emailing page.
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

Verification of $OUTPUT

Post by edweill »

I recorded the strlen of both the text and html versions of my email and both verified that the strlen of the variable and the $OUTPUT variable matched and also output the contents of $OUTPUT to the web page. All of this shows that $OUTPUT is properly formatted when passed to swift in the

Code: Select all

$message->attach(new Swift_Message_Part($OUTPUT['html'], "text/html"));
Yet, about 1/3 to 1/2 the time we are getting cut off html at reciept. I removed the <style> in the <head>, so we are now getting some visual output, but it is ending abruptly.

These data can be fairly long - more than 10,000 characters, but the cutoff is happening even with 4000-5000 character strings, and sometimes even the very long outputs come through successfully. Without the available file attachements we are talking 5 to 20 kb, which doesn't seem big. The file attachments come through just fine.

I am running the PHP 4 version of swift on a PHP 4.4 apache server (phpinfo)

Is there some possibility of some smtp setting at the server (ISP) that could cause this?

I can't imagine that it would work better to save the $OUTPUT as a temp file, then stream the file through then erase the file. (Would it? I am getting a little desperate!)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Exim has a max message size and can be set to truncate the message, or drop it. I'm not sure about other MTAs. It sounds as though your problem is more sporadic than that though. Is it always cutting it the same length?
chuckl
Forum Commoner
Posts: 61
Joined: Wed May 23, 2007 7:36 am

Post by chuckl »

Don't wish to hijack the thread, but rather to confirm that I have seen this or something similar while testing on a qmail and a Postfix server, but the email was always truncated in the header, no body at all.

Typical bottom of header results when it happened:

Subject: Test SMTP -t yet again
Date: Sun, 27 May 2007 15:48:55 +0100
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_=_swift-154255812946599a57ac42c5.33604386_=_"
Content-Transfer-Encoding: 7bit
Message-ID: <20070527144855.9483.494884997.swift@xxx.xxxx.xxxxxxxxxx.xx>
From: The Test Store <xxxxx.xxxxxxx@xxxxx.xxx>
X-Virus-Status: No
X-Virus-Checker-Version: clamassassin 1.2.4 with clamscan / ClamAV 0.90.2/3304/Sun May 27 05:35:19 2007

or

Subject: SMTP, CER Server, Swiftmail, 8 bit
Date: Mon, 28 May 2007 14:40:15 +0100
X-LibVersion: 3.2.4_4
MIME-Version: 1.0
Content-Type: multipart/alternative; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <20070528134015.24834.922678721.swift@www.xxxxxxxx.xx.xx>
X-Virus-Status: No
X-Virus-Checker-Version: clamassassin 1.2.4 with clamscan / ClamAV 0.90.2/3311/Mon May 28 01:21:25 2007

Very wierd encodings and charsets would appear, rest of the header was normal
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

message length

Post by edweill »

on multiple sendings of the same message it appears to stop at the same place. With different messages it moves around a bit, but does not seem to correlate directly to the character count.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: message length

Post by Chris Corbyn »

edweill wrote:on multiple sendings of the same message it appears to stop at the same place. With different messages it moves around a bit, but does not seem to correlate directly to the character count.
Are you able to send me a copy of the code or is it very tied into your working setup? I'd like to try recreating it since I can't think of any good reason why this should happen. Text gets passed through wordwrap()... I wonder if there could be an issue there.

The weird thing is, I've sent 100MB+ emails with Swift to prove a point about its memory management features with disk caching and those all worked fine.

There is one way to tell what Swift is about to send too:

Code: Select all

$stream =& $message->build();
echo "<pre>" . $stream->readFull();
If the message is truncated there then it's definitely being truncated before reaching the SMTP server. If it's not truncated there then something is going wrong later.

Does this only happen when sending out lots of emails in one go?
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

That will help!

Post by edweill »

the code snippet

Code: Select all

$stream =& $message->build(); 
echo "<hr><br><pre>" . $stream->readFull();

echo "<br><hr></pre>";
will definately help! I have inserted it just before both actual sends. I am guessing that the output will be sending the whole document and that the problem is not with swift. The difficulty then comes down to getting to the right person at the ISP to find out what is going on there.

I provided earlier the entirety of the swift code, so I am not sure what code you are asking for. I will email you the output from the code snippet, since I have one that showed complete output ( and the email was complete also when it arrived).


Anyway, I will continue testing till either I get a broken stream output and/or a broken email.

Does the build() do anything that might affect this? I assume that it is called within the send, but do not know. I only ask because since I included the snippet, I have had only successful emails (granted it is only 3, but it seems like a coincidence.)
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

more

Post by edweill »

Oops, I forgot to say that this happens even when the email is only sent to one recipient.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hi, thanks I got your email :) I'll look at it later since I' just heading to work now. I'm confused if what you sent me is supposed to be truncated though? Did it look like it was truncated before being sent, or is it being truncated later? :)
edweill
Forum Newbie
Posts: 11
Joined: Fri May 25, 2007 9:12 am

email

Post by edweill »

What I sent was not truncated.

Since I added the

Code: Select all

$stream =& $message->build(); 
echo "<hr><br><pre>" . $stream->readFull(); 

echo "<br><hr></pre>";
I have not gotten a truncated email. Hopefully, during today's testing we will get one and be able to tell if it is in the code or the Server.
Post Reply