SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with PHP Mail

    Hi:

    I've set up a web-based utility in PHP that allows one of my clients to type (or paste) in the contents of an e-mail message that he then sends to a mailing list, which is maintained in a database (MySQL).

    The textarea field is as follows:

    <textarea rows="20" name="message" cols="65" wrap="hard"></textarea>

    I do it this way because I've heard (and seen for myself) that some e-mail readers don't properly wrap lines (and some not at all) and that 65 characters is the maximum "safe" number of characters to use per line.

    Unfortunately, although I think the percentages are rather small, my client does get responses from some people on his mailing list saying that the entire e-mail is jumbled up into a single paragraph, for instance.

    After the PHP script receives the form input, the following lines are executed:

    PHP Code:
    $message=stripslashes($message);
    $message=ereg_replace("\n","",$message); 
    I arrived at these lines primarily through trial-and-error. Without them, when I did tests, the e-mails had slashes in front of all apostrophes; for example: don\'t. And wherever there was a blank line entered by the client, two blank lines would appear in the e-mail.

    The actual mail command is as follows:

    PHP Code:
    mail($mailto,$subject,$message,"Return-Path: " $emailfrom "\r\nSender: " $emailfrom "\r\nFrom: " $emailfrom "\r\nReply-To: " $emailfrom "\r\nErrors-To: " $emailfrom); 
    When I do tests and receive the e-mails in Netscape Messenger, they look perfect. And when I try to fix the problem for one person, it screws it up for someone else who previously could read it just fine.

    I've tried explaining to my client that we may not be able to get it perfect for everyone due to differences in how different e-mail readers present incoming messages, but he's skeptical. I hate to tell him "Sorry, I can't fix it any better than it is", but I don't know what choice I have.

    Any advice out there? THANKS!

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First off use str_replace not ereg_replace since you don't need to use an expression.

    PHP Code:
    $message=str_replace("\n","",$message); 
    Next use wordwrap

    PHP Code:
    $message wordwrap($message65"\n"); 
    This will break up the string at every 65th character with a \n.

    http://www.php.net/wordwrap
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict
    Join Date
    May 2001
    Location
    hong kong
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for characters of unicode...this may not work...
    any amendment??

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for characters of unicode...this may not work...
    Well.......... Try It!
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Addict
    Join Date
    May 2001
    Location
    hong kong
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried it ...
    unwork (just like incapacity of funtion substr on unicode)


Bookmarks

Posting Permissions

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