Page 2 of 2
$stream =& $message->build();
Posted: Sat Jun 02, 2007 10:08 am
by edweill
In the testing with the snippet in place, we had no truncated emails, so I tried testing without it and started getting them again.
I have found that every time I have the build code before the send, it comes through fine.
If I comment out that code, it sometimes comes through truncated.
In one test, I had the line of code active for one of the two emails and not the other. The one with the code came through fine, but the other was truncated!
I am using PHP 4 version on a PHP 4.4 server.
Posted: Sat Jun 02, 2007 10:34 am
by Chris Corbyn
How very strange. The internals of Swift use some string caching system created by myself. Basically, once the first email has been sent the results of the rendered string are cached in memory (or on disk of the disk cache is used). Subsequent sends (mostly) use that cached data. It should theoretically be no different doing this:
Code: Select all
$message->build();
$swift->send($message, ..., ... );
If you're sure that this is what's making the difference then I can narrow this right down. FYI, if you're sending more than one message, writing your code like I just did above is going to have very little performance overhead due to the caching just to put your mind at rest.
two emails
Posted: Sun Jun 03, 2007 11:56 am
by edweill
I think you misunderstood - My code sends out two different emails. One to the one multipart html/plain text to the recipient list and a plain text only copy to our fullfillment center.
In the mixed scenario I had the build before the send on the html/plain text email send but not on the plain text only copy. The html/plain text version came through properly, but the plain text only version was truncated. There was no caching between the two since they were different messages with different content.
Posted: Thu Jun 14, 2007 4:48 pm
by dantahoua
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello, I already had this problem, I was thinking it was because of UTF-8 encoded html-part, but it seems not... I now have the same problem again, also with php4. My mail are always truncated, even if I send it to only one recipient.
Here is the code for sending:
Code: Select all
if (isset($_POST['Inscription']))
{
require_once('Class/CourrielCollection.php');
require_once('Class/Swift.php');
require_once('Class/Conf_mail.php');
require_once('Class/Template.php');
$objconf = new Conf_mail(1);
/******** Ajout de courriels **********************************/
if (Courriel::verifierCourrielExiste(mysql_real_escape_string($_POST['courriel'])))
{
$fr_mess_erreur = 'L\'adresse de courriel suivante est déjà présente dans le système : '.$_POST['courriel'];
}
else
{
if (isset($_POST['groupes']))$tabgrp = $_POST['groupes'];else $tabgrp = null;
$chaineconf = Courriel::insertTempCourriel(mysql_real_escape_string($_POST['nom']),mysql_real_escape_string($_POST['prenom']),mysql_real_escape_string($_POST['courriel']),1,$tabgrp);
/******** Envoie du courriel de confirmation **********************************/
if ($objconf->GetSmtp_mode() == 1)
{
require_once('Class/Swift/Connection/SMTP.php');
$swift =& new Swift(new Swift_Connection_SMTP($objconf->GetSmtp_host(),$objconf->GetSmtp_port()));
}
else
{
require_once('Class/Swift/Connection/NativeMail.php');
$swift =& new Swift(new Swift_Connection_NativeMail());
}
//Création du message
$message =& new Swift_Message('Abonnement');
//Création des parties du message multipart
//Partie text ->
$text_part = "Vous êtes ".$_POST['nom']." ".$_POST['prenom']." et vous avez demandé à vous abonner aux bulletins d'informations de la Coalition pour l'arrondissement historique de Sillery.\n\r
Vous devez confirmer cette demande en copiant le lien suivant dans votre fureteur.\n\r
".$objconf->GetBase_url()."/index.php?url=Abonnement&courriel=".$_POST['courriel']."&conf=".$chaineconf;
//Partie html ->
//Remplissage du template
$template = new template('Cryo/Modules/Mail/Templates/Conf'.$objconf->GetTemplate());
//Remplace titre, header, footer et texte dans le template
//$template->assign('IMG_HEADER','http://www.csaq.org/Cryo/uploads/mail/csaq_head.jpg');
$template->assign('NOM',$_POST['nom']);
$template->assign('PRENOM',$_POST['prenom']);
$template->assign('COURRIEL',$_POST['courriel']);
$template->assign('CONF',$chaineconf);
//On récupère le template dans une variable
$html_part = $template->__toString();
//On attache les partie texte brut et html au message
$message->attach(new Swift_Message_Part($text_part));
$message->attach(new Swift_Message_Part($html_part, "text/html"));
//Ajout d'un return_path
$message->setReturnPath($conf['return_path']);
//Envoi du mail
if ($swift->send($message, new Swift_Address($_POST['courriel'], $_POST['nom']." ".$_POST['prenom']), new Swift_Address($objconf->GetFrom_email(), $objconf->GetFrom_name()))) $fr_mess_erreur="Un courriel de confirmation vous a été envoyé.<br/>Vous devez y répondre pour confirmer votre inscription. Merci !";
else $fr_mess_erreur = "Un problème technique est arrivé, veuillez recommencer ou nous contacter, merci.";
}
}
and here is the template:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="author" content="Point d'encre" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="robots" content="all" />
<title>..:: Coalition pour l’arrondissement historique de Sillery ::..</title>
<script type="text/javascript" src="Inc/fnc.js"></script>
<link rel="Shortcut Icon" type="image/x-icon" href="favicon.ico" />
<style type="text/css" media="all">@import "http://www.sillery-joyau.ca/Css/Style.css";</style>
</head>
<body onload="window.defaultStatus='Sillery';" id="Sillery">
<div id="Contenant" style="width: 600px;">
<div id="Intro" style="width: 600px;height: 66px;">
</div>
<div id="Page" style="width: 600px;">
<div class="texte">
Bonjour {PRENOM} {NOM},<br/>
vous avez demandé à vous inscrire au bulletin d'information de<br/>
la coalition pour l'arrondissement historique de Sillery.<br/>
<a href="http://www.sillery-joyau.ca/index.php?url=Abonnement&courriel={COURRIEL}&conf={CONF}" >Cliquez ici pour confirmer votre inscription.</a><br/>
</div>
<br style="clear:both;"/> <!--Permet au contenant de grandir en fonction du contenu-->
</div>
<div id="Footer">
<div id="Menu_Footer">
<ul>
<li class="un"><a href="http://www.sillery-joyau.ca/index.php?url=Politique" title="Politique de confidentialité"><span>Politique de confidentialité</span><!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li class="deux"><a href="http://www.sillery-joyau.ca/index.php?url=Abonnement&courriel={COURRIEL}&conf={CONF}" title="Abonnement"><span>Abonnement</span><!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li class="trois"><a href="http://www.sillery-joyau.ca/index.php?url=Desabonnement" title="Désabonnement"><span>Désabonnement</span><!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li class="quatre"><a href="http://www.sillery-joyau.ca/index.php??url=Coord" title="Coordonnées"><span>Coordonnées</span><!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
</ul>
</div>
<span class="info">© 2007 CAHDS, Tous droits réservés.</span>
</div>
</div>
</body>
</html>
The mail are always truncated after link rel=3D"Shortcut Icon" type=3D"image/x-icon" href=3D"favicon.ico" />
I tried to put an 'echo' on my $html_part just before sending it to swift, and it's alright.
I'll try your "stream" trick to see if it resolve my problem.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Jun 14, 2007 4:56 pm
by dantahoua
Ok, i did the same as the last time, I remove every UTF-8 encoded text from my template (Coordonnées became Coordonnées), and miracle... It's working!!
Seems to be a problem with php4 and UTF-8, this time there is no decoration plugin, just swift...
I'll try one day with php5 to see if the problem is still there (no supposed to change anything but sometimes...)
Really strange!
Re: randomly cut off emails.
Posted: Wed Jun 20, 2007 7:58 am
by Duane
Dear Edweill and Chris,
I wanted to add that I have also been experiencing cut off emails, with no discernable pattern of what makes them cut off. The emails are plain text, non-multipart, averaging around 20-50 lines of text. The message body is passed to Swift_Message as a string. There are 20-40 recipients and from what I can tell, all of the recipients receive the same cut off emails. I use the Swift_BatchMailer send method. I turned off Swift_Cache_Disk, which I was using, but the cutoffs persisted.
I inserted $message->build() before my send and since then (about ten emails), the messages are no longer cut off.
I am using version 3.2.5.
I'm curious to understand the source of the cutoffs, if it's discovered.
Best,
Duane.
Posted: Wed Jun 20, 2007 2:40 pm
by Chris Corbyn
/me scratches head... build() is called internally either way. This is going to be something very simple, but obscure. FYI, I'm not releasing any new code until v3.3 (before the end of June) so I'll aim to have this one ironed out by then.
(Isn't it funny how nobody posts bugs on SourceForge?

This forum has become a bug tracker

)
Posted: Fri Jul 20, 2007 8:07 am
by Chris Corbyn
/digs up old problem/post...
I've just had an interesting email regarding the "blank email" problem some people have been having. Fortunately this time the exact bit of text causing the problem was sent to me. I spotted that the text looked garbled when I opened the file in nano (a basic editor), then opening in Kate told me the file was a binary file.
I identified a NUL byte in the exact bit of text which was causing the problem. NUL bytes in text files cause corruption of the data and I think this is the root cause of these problems.
Why would there be a NUL byte in there? Honestly, I don't know, Swift doesn't do it, the text editor the code has been written in has done this. It's also possible that a copy & paste operation somewhere has introduced a problem, or data taken from MySQL with a corrupt character set.
if anyone is getting the truncated message issue, or a blank email when they're not expecting it, please try using this script to check if it's the same bug:
Code: Select all
<?php
define("CHECK_FILE", "foo.php");
$data = file_get_contents(CHECK_FILE);
if (strpos($data, chr(0)) !== false)
{
echo "File is corrupt.";
}
else
{
echo "File looks good.";
}
Basically, look for NUL bytes (ordinal value 0).
it's the dang periods!!!
Posted: Thu Jul 26, 2007 3:52 pm
by aedmonds
I've been running into this same problem (cut-off emails) from time to time for the past two months since I started using SwiftMailer and I think I know what the problem is... (at least mine)
It seems to be that the email messages are cut off when the MTA receives the email all because of the specific placement of periods (.) in the email. I found this recently while researching CSS in emails. I came across this blog posting (
http://mailchimp.blogs.com/blog/2006/01 ... _imag.html) and learned something new when I came to the
Periods = "Stop Email!" section.
I've gone back with emails that were known to be truncated and found that the email source just completely stops right before a period was supposed to be.
Maybe I'm totally off here but this seems to be the common thread with my emails being cut off.
Thank you so much for SwiftMailer! It truly is an amazing product!
I can post source examples here or provide a link to my own server. Which would you prefer?
-Aaron
Posted: Thu Jul 26, 2007 4:13 pm
by aedmonds
Should I report the above problem as a bug on SourceForge? It looked kind of dead.
Just let me know.
-Aaron