mail() and To: headers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Soper

    mail() and To: headers

    I'm using the mail() function to send e-mails. The first argument to the
    function is the e-mail address the mail will be sent to. I understand this
    should just be in the format 'address@domain ' and not '"Name"
    <address@domain >' and that if I want to specify the name of the recipient as
    well as the address of the recipient I should pass it as an addition header.
    This works fine locally under Windows and Apache but remotely under Linux
    and Apache the resultant raw message has 2 To: headers meaning the client
    displays it as being sent to 2 addresses (the same address twice). Am I
    doing this correctly? It seems a clumsy way of doing it, especially as
    SpamAssassin marks down a message with only an email address in the two
    header.

    Thanks,
    Geoff


  • Pedro Graca

    #2
    Re: mail() and To: headers

    Geoff Soper wrote:[color=blue]
    > I'm using the mail() function to send e-mails. The first argument to the
    > function is the e-mail address the mail will be sent to. I understand this
    > should just be in the format 'address@domain ' and not '"Name"
    > <address@domain >'[/color]

    I've been using it with the first format without problems.




    $ uname -srmo
    Linux 2.4.26-1-686 i686 GNU/Linux

    $ php -v
    PHP 4.3.4 (cli) (built: Mar 27 2004 08:04:22)
    Copyright (c) 1997-2003 The PHP Group
    Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

    $ cat mailgeoff.php
    cat mailgeoff.php
    <?php
    mail('"Geoff Soper" <geoff.news@alp haworks.co.uk>' ,
    'test',
    'seems to have worked :-)',
    'From: Pedro Graca <hexkid@hotpop. com>',
    '-fhexkid@hotpop. com');
    ?>

    $ php mailgeoff.php

    $

    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    • John Dunlop

      #3
      Re: mail() and To: headers

      Pedro Graca wrote:
      [color=blue]
      > Geoff Soper wrote:
      >[color=green]
      > > I'm using the mail() function to send e-mails. The first argument to the
      > > function is the e-mail address the mail will be sent to.[/color][/color]

      Basically, yes. The documentation's examples *imply* that the first
      parameter should be a comma-and-space-separated list of one or more
      addr-specs, but I can't find where this is explicitly stated.
      [color=blue][color=green]
      > > I understand this should just be in the format 'address@domain '[/color][/color]

      To send mail to a single mailbox, probably.
      [color=blue][color=green]
      > > and not '"Name" <address@domain >'[/color][/color]

      Again, that's probably correct; the docs are waffly.
      [color=blue]
      > I've been using it with the first format without problems.[/color]

      OK. But read the Manual's note, which feigns a quotation:

      | The to parameter should not be an address in the form of "Something
      | <someone@exampl e.com>". The mail command may not parse this properly
      | while talking with the MTA (Particularly under Windows).

      "PHP: mail - Manual",


      And there are related user-comments dated 2003-01-17 and 2003-06-09:




      We're left wondering what the Manual's preferred forms are. Had it
      referenced RFC2822, and stated that the first parameter to mail should
      be a comma-[and-space-]separated list of addr-specs, our questions
      would be answered. As it is, we have to guess.

      --
      Jock

      Comment

      • Geoff Soper

        #4
        Re: mail() and To: headers

        > Pedro Graca wrote:[color=blue]
        >[color=green]
        > > Geoff Soper wrote:
        > >[color=darkred]
        > > > I'm using the mail() function to send e-mails. The first argument to[/color][/color][/color]
        the[color=blue][color=green][color=darkred]
        > > > function is the e-mail address the mail will be sent to.[/color][/color]
        >
        > Basically, yes. The documentation's examples *imply* that the first
        > parameter should be a comma-and-space-separated list of one or more
        > addr-specs, but I can't find where this is explicitly stated.
        >[/color]
        [color=blue]
        > | The to parameter should not be an address in the form of "Something
        > | <someone@exampl e.com>". The mail command may not parse this properly
        > | while talking with the MTA (Particularly under Windows).
        >[/color]

        Reading this excerpt from the manual again, is it the case that any mail
        server the message might pass through potentially might have a problem or is
        it just the SMTP server my script talks to directly? If it's the latter then
        it works so it must be OK for me to use but if it's the former then it's
        about taking a chance.

        Any suggestion?

        Thanks,
        Geoff


        Comment

        • John Dunlop

          #5
          Re: mail() and To: headers

          Geoff Soper wrote:
          [color=blue]
          > [From <http://www.php.net/manual/en/function.mail.p hp>:]
          >[color=green]
          > > | The to parameter should not be an address in the form of "Something
          > > | <someone@exampl e.com>". The mail command may not parse this properly
          > > | while talking with the MTA (Particularly under Windows).[/color]
          >
          > Reading this excerpt from the manual again, is it the case that any mail
          > server the message might pass through potentially might have a problem or is
          > it just the SMTP server my script talks to directly?[/color]

          Just the SMTP server your script talks to directly.

          Conversations between user-agents and MTAs are private matters. What
          happens after that, however, is covered in RFC2821.

          RFC2821, Simple Mail Transfer Protocol,


          --
          Jock

          Comment

          Working...