Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts

    E-mail message composition problems

    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.
    PHP Code:
    Content-Typetext/plaincharset=iso-8859-1
    X
    -MailerPHP/" . phpversion(); 
    It looks like this in the e-mail
    Code:
    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
    PHP 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!"


  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    try this instead:

    PHP Code:
    $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!"
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks R.J....You help did cut down on some of the lines & spaces, but not all.

    This is what it looks like now
    PHP Code:
    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
    :

    Usernamelansing

    Password
    K0K95S58XM

    Thanks
    !,

    -
    Jason

    Site Name

    This is an automated activation e
    -mailplease do not reply

  • #4
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/

  • #7
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by lansing
    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.

  • #9
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the fast response. That is exactly what I am looking for. I will post if I need help with Swift Mailer.

  • #10
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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->errors1).". Log: ".print_r($mailer->transactions1);

    ?>
    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.

  • #11
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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:
    PHP 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->errors1).". Log: 
    "
    .print_r($mailer->transactions1);


    print_r($mailer->transactions); 

  • #13
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh you've found a bug

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

    From:
    PHP Code:
    $this->baseObject->logError('Authentication failed using PLAIN'$this->responseCode); 
    To:
    PHP Code:
    $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.

    PHP Code:
    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->errors1).". Log: 
    "
    .print_r($mailer->transactions1); 
    Last edited by d11wtq; 06-30-2006 at 07:04 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •