Hello.

I've got an email script. The $message is more than 300 characters. I'm not using the wordwrap() function (wordwrap is recommended by the PHP Manual).

The script works fine without using the wordwrap() function. I can apply the wordwrap function and the script works the same (the email looks the same in the email box) as it does without wordwrap.

The PHP Manual, as far as I can tell, does not give a reason for using the wordwrap function.

My email script use the <html> tags. It may be that wordwrap() is not necessary if I use the <html> tags.

How come the PHP Manual says to use the wordwrap function?

The PHP Manual says this:

$message
Message to be sent.
Each line should be separated with a LF (\n). Lines should not be larger than 70 characters.

// The $message is about 300 characters long.
// The href="http://........." part alone is more than 70 characters.
$message = <html><body><p>Regis... <a href="http://........."><click here</a>...";
$message = wordwrap($message, 70);
mail('mail_to@example.com', 'My Subject', $message);

// It's sending mail ok just like this (without wordwrap):
$message = <html><body><p>Regis... <a href="http://........."><click here</a>...";
mail('mail_to@example.com', 'My Subject', $message);

Thanks.

    sometimes a mta may encounter problems if the lines are too long and ! will start showing up in the message. the rfc822 doesnt say anything about wrapping the body, but I think it stems from when people would read mail on terminals which had a limited width.

      drew010

      Thanks for responding. I appreciate the help.

      I also got to write a script that will send an email newsletter to many subscribers.

      I guess that I'm going to have to start studying up on sending email. The PHP Manual also says that if you're sending Html (which I'm doing) then you need to use PEAR:: Mail.

      It's my understanding that the mail() function works ok for sending just one email (like from a form) but if you're going to loop through and send multiple emails you need a more sophisticated program. The mail() function opens and closes the socket each time it sends a mail - which causes the scrtipt to time-out.

      I've looked at the PEAR::Mail scripting. It looks complicated. I might spend 2 or 3 days trying to figure it out and still not get it to work.

      There's another program that I found at SourceForget called "PHPMailer". It looks about as difficult as the PEAR::Mail.

      Can anybody point me toward a tutorial about how to write a script or class that will send Html and/or handle a loop for multiple email addresses (like for a newsletter) so I won't have to use the PEAR::Mail class?

      Thanks.

        sending html in the regular mail function is fine, theres no reason to use pear just for that. it is true that sending a large amount of emails is resource intensive, but ive sent a few thousand emails using php with no troubles.
        i have found a call to usleep with some fraction of a second pause after each mail call will help reduce the load a little bit as well.

          also to sending a html format you need to add a mime type to headers.

          // To send HTML mail, you can set the Content-type header. 
          $headers = "MIME-Version: 1.0\r\n";
          $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
          mail('mail_to@example.com', 'My Subject', $message,$headers);  

          hope that help.

            As it happens, RFC2822 does specify line-length limits:

            2.1.1. Line Length Limits
            There are two limits that this standard places on the number of characters in a line. Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF.

              I have found a tutorial about how to install the PHPMailer script (it's SourceForce.net, typo earlier, sorry) on the PHP Freaks web site
              http://www.phpfreaks.com/tutorials/130/0.php

              I've got into the first part of it. It looks like he (the author) might know what he's talking about but I got to get further into the tutorial and see if I can get the PHPMailer classes to work before I can be sure.

              I'll report my findings about the tutorial back here to this thread. It might be a week or two.

                24 days later

                I'm just touching bases back and reporting my findings about the tutorial on the PHP Freaks web site.

                The tutorial has got ten pages. I've worked my way through the first seven pages. The last two or three pages goes into sending a mailing list.

                The first part of the tutorial shows the user how to get up and running with the PHP Mail program.

                On page two it shows you how to create a config.php file and then has examples that shows the user how to send just one mail.

                I just copied and pasted the script and it sent an Html email to my own email address. It worked fine.

                I've not studied it in detail or anything but it looks like (on Page 8) of the tutorial that you can bypass the mail() function and therefore not have to worry about the opening and closing of the socket (which solves my problem above).

                Page 8 says that you can use the "external SMTP servers" and not the "localhost." I take that to mean that they are bypassing the mail() function.

                Hope this helps.

                  Write a Reply...