...

View Full Version : E-mail message composition problems



lansing
06-25-2006, 03:16 AM
I am using the simple mail() function to send an activation link out. I have tested this on several free e-mail providers. For some reason on some of them I am getting double line spaces where there should be only 1 line break & some places 3 line breaks where there should only be 2 breaks. I have posted the way it looks in the e-mail & my code. It should look like the code does as far as the line breaks & line spaces.

I am using this in my headers code if it matters since I am only using plain text.

Content-Type: text/plain; charset=iso-8859-1
X-Mailer: PHP/" . phpversion();

It looks like this in the e-mail
Dear Jason Andrews,


Thank you for registering an account at http://www.domain.com!




You are two steps away from logging in and accessing our your members area.




To activate your membership,


please click here:
http://www.domain.com/activate.php?variable1=1070&variable2=6760d7bdd94d46b6041
516a587931540




Once you activate your memebership, you will be able to login


with the following information:




Username: lansing


Password: Z5HHHCK7UT




Thanks!


-Jason


Site Name




This is an automated activation e-mail, please do not reply!

This is my code
$userid = mysql_insert_id();
$subject = "Activation link for Domain Name!";
$message = "Dear $first_name $last_name,
Thank you for registering an account at http://www.domain.com!

You are two steps away from logging in and accessing our your members area.

To activate your membership please click the line below:
http://www.domain.com/activate.php?activate=$variable1&p=$variable1

Once you activate your memebership, you will be able to login
with the following information:

Username: $username
Password: $random_password

Thanks!
-Jason
Domain

This is an automated activation e-mail, please do not reply!";

chump2877
06-25-2006, 06:18 AM
try this instead:


$userid = mysql_insert_id();
$subject = "Activation link for Domain Name!";
$message .= "Dear $first_name $last_name,\n\n";

$message .= "Thank you for registering an account at http://www.domain.com!\n\n";

$message .= "You are two steps away from logging in and accessing our your members area.\n\n";

$message .= "To activate your membership please click the line below:
http://www.domain.com/activate.php?activate=$variable1&p=$variable1\n\n";

$message .= "Once you activate your memebership, you will be able to login
with the following information:\n\n";

$message .= "Username: $username\n";
$message .= "Password: $random_password\n\n";

$message .= "Thanks!\n";
$message .= "-Jason\n";
$message .= "Domain\n\n";

$message .= "This is an automated activation e-mail, please do not reply!";

lansing
06-25-2006, 12:45 PM
Thanks R.J....You help did cut down on some of the lines & spaces, but not all.

This is what it looks like now
Dear Bla Bla,

Thank you for registering an account at http://www.domain.com!

You are two steps away from logging in and accessing our your members area.

To activate your membership please click the line below:


http://www.domain.com/activate.php?variable1=0&variable2=bc52ab14519ebaa50ed0d2
2a38e11ce3

Once you activate your membership, you will be able to login


with the following information:

Username: lansing

Password: K0K95S58XM

Thanks!,

-Jason

Site Name

This is an automated activation e-mail, please do not reply!

d11wtq
06-26-2006, 12:30 AM
I think some MTAs are adding \r\n to the end of the lines thus resulting in \n\r\n which on some clients will appear as two spaces. This is down to compliancy and IETF standards. RFC 2821 defines that the only places \r or \n can occur in the email is as line ending in a CRLF sequence (i.e. \r\n).

In short, use \r\n to end your lines.

Swift Mailer will handle this for you automatically if you're pulling this text from a database or such like and don't wish to convert yourself.

lansing
06-28-2006, 02:20 AM
Thanks...it stopped the double lines in some e-mail providers, but not all. There has to be a way to stop the line breaks with all or most e-mail providers.

d11wtq
06-28-2006, 07:01 PM
I have no idea why it's not working :? Do you wanna download Swift Mailer and send the same email with it then see how it looks even if you don't plan on using Swift?

http://www.swiftmailer.org/

lansing
06-29-2006, 02:44 PM
On that Swift Mailer...it says it has Multipart messages. I know there is text/plain & text/html composition types.

With the Multipart messages feature...will that allow me to have an HTML & plain text version & then the user's e-mail client/software will display the html version if it supports it & if doesn't support html e-mail then it will display the plain text version of the e-mail?

d11wtq
06-29-2006, 02:51 PM
On that Swift Mailer...it says it has Multipart messages. I know there is text/plain & text/html composition types.

With the Multipart messages feature...will that allow me to have an HTML & plain text version & then the user's e-mail client/software will display the html version if it supports it & if doesn't support html e-mail then it will display the plain text version of the e-mail?

Exactly ;)

You just call addPart() twice. One with your HTML body, and one with your plain-text body. The when you send the email (leave out the 4th parameter in send()!) the client will display what it can.

lansing
06-29-2006, 02:56 PM
Thanks for the fast response. That is exactly what I am looking for. I will post if I need help with Swift Mailer.

lansing
06-29-2006, 08:55 PM
The Swift Mailer is confusing on how to get it to work. The instructions page doesnt match the actual files in the download. This is what I have done so far & still I just get a blank page when I try to go to the test.php page as the instructions say.

Here is the instructions page: http://www.swiftmailer.org/documentation/5#view
According to the instructions page on lines 17 & 18 I am to type my name & e-mail address twice. Why...what is the purpose of that?

This is what my basic_smtp.php page looks like
<?php

require('../../Swift.php');
require('../../Swift/Swift_SMTP_Connection.php');

//The mailer will now establish a connection with the server
$mailer = new Swift(new Swift_SMTP_Connection('smtp.comcast.net'));

//If anything goes wrong you can see what happened in the logs
if (!$mailer->hasFailed()) //Optional
{
//Sends a simple email
$mailer->send(
'"Joe Bloggs" <joe@bloggs.com>',
'"Your name" <you@yourdomain.com>',
'Some Subject',
"Hello Joe it's only me!"
);
//Closes cleanly... works without this but it's not as polite.
$mailer->close();
}
else echo "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log: ".print_r($mailer->transactions, 1);

?>


I uploaded to a testing folder " mail " that is in my root directory.
I change this line $mailer = new Swift(new Swift_SMTP_Connection('smtp.somedomain.com')); to match my web server.

I am just getting a blank page.

d11wtq
06-29-2006, 11:38 PM
The two email addresses are "To:" and "From:" ... the documentation explains that under send().

The blank page.... that suggest there's a fatal error and you have error_reporting turned off.

Put error_reporting(E_ALL) at the top of your code and have another go. Make sure you're using the PHP4 version if you have PHP4.... the PHP5 version will give you fatal errors prior to version 1.3.

lansing
06-30-2006, 02:06 AM
This Swift Mailer just doesn't make any sense. The documentation on their site sucks. I have spent hours on this Swift Mailer & have gotten nothing to work. I get the following error: Notice: Undefined property: responseCode in /home/httpd/vhosts/domain.com/httpdocs/mail/Swift-1.3.1-php4/Swift/Swift_PLAIN_Authenticator.php on line 104
Didn't authenticate to serverArray ( [0] => Array ( [command] => [time] => 0.74422600 1151629418 [response] => 220 phobos.dns-shield.com ESMTP ) [1] => Array ( [command] => EHLO www.domain.com [time] => 0.90768300 1151629424 [response] => 250-phobos.dns-shield.com 250-AUTH=LOGIN CRAM-MD5 PLAIN 250-AUTH LOGIN CRAM-MD5 PLAIN 250-STARTTLS 250-PIPELINING 250 8BITMIME ) [2] => Array ( [command] => AUTH PLAIN [time] => 0.91016100 1151629424 [response] => 334 ok. go on. ) [3] => Array ( [command] => aW5mbwBpbmZvAHBsZXNrY2x1Yg== [time] => 0.91033700 1151629424 [response] => 535 malformed input ) )

I have the following code:
error_reporting(E_ALL);

require('../../Swift.php');
require('../../Swift/Swift_SMTP_Connection.php');

///The mailer will now establish a connection with the server
$mailer = new Swift(new Swift_SMTP_Connection('smtp.sitename.com'));

//If anything goes wrong you can see what happened in the logs
if (!$mailer->hasFailed()) //Optional
{
//You can call authenticate() anywhere before calling send()
if ($mailer->authenticate('username', 'password'))
{
//Sends a simple email
$mailer->send(
'"Joe Bloggs" <abc@comcast.net.com>',
'"Your name" <abc@hotmail.com>',
'Some Subject',
"Hello Joe it's only me!"
);
}
else echo "Didn't authenticate to server";

//Closes cleanly... works without this but it's not as polite.
$mailer->close();
}
else echo "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log:
".print_r($mailer->transactions, 1);


print_r($mailer->transactions);

d11wtq
06-30-2006, 07:00 AM
Oh you've found a bug :)

Open up the file Swift_PLAIN_Authenticator.php and change on line 104:

From:

$this->baseObject->logError('Authentication failed using PLAIN', $this->responseCode);

To:

$this->baseObject->logError('Authentication failed using PLAIN', $this->baseObject->responseCode);


Sorry about that.

I'll put a new release out later today.


This Swift Mailer just doesn't make any sense. The documentation on their site sucks.

Thanks :(

Could you elaborate and what sucks about the documentation? I'd appreciate input on things like that if people are struggling. As it was, your problem was due to a bug.

I can honestly say that out of the hundreds using it in large projects over the first month of releasing it you're the first to complain :(

EDIT | Another workaround if you don't want to patch the source is to use LOGIN authentication.



error_reporting(E_ALL);

require('../../Swift.php');
require('../../Swift/Swift_SMTP_Connection.php');
require('../../Swift/Swift_LOGIN_Authenticator.php');

///The mailer will now establish a connection with the server
$mailer = new Swift(new Swift_SMTP_Connection('smtp.sitename.com'));
$mailer->loadAuthenticator(new Swift_LOGIN_Authenticator);

//If anything goes wrong you can see what happened in the logs
if (!$mailer->hasFailed()) //Optional
{
//You can call authenticate() anywhere before calling send()
if ($mailer->authenticate('username', 'password'))
{
//Sends a simple email
$mailer->send(
'"Joe Bloggs" <abc@comcast.net.com>',
'"Your name" <abc@hotmail.com>',
'Some Subject',
"Hello Joe it's only me!"
);
}
else echo "Didn't authenticate to server";

//Closes cleanly... works without this but it's not as polite.
$mailer->close();
}
else echo "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log:
".print_r($mailer->transactions, 1);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum