Why can't I send a mail with PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Mueller

    Why can't I send a mail with PHP

    I can't send a mail with the following mail header:
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "From: \"User\" <user@inter. net>\n";

    Therefore $headers is set to (echo $header;)
    MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 From: "User"
    <user@inter.net >

    The mail has not been delivered and my PHP server says:
    [24-Nov-2005 00:37:19] PHP Warning: mail() [<a
    href='function. mail'>function. mail</a>]: SMTP server response: 501 5.5.4
    Invalid Address in C:\PHP\file.php on line 132


    If I use
    $headers .= "From: user@inter.net\n";
    instead of
    $headers .= "From: \"User\" &lt;user@inter. net&gt;\n";
    is works perfect.

    What's wrong?
    Stefan


  • SC

    #2
    Re: Why can't I send a mail with PHP

    Don't use &lt; and &gt;. Use the actual characters < and >.


    "Stefan Mueller" <seekware-remove-@yahoo.com> wrote in message
    news:dm30pb$1e9 u$1@news.imp.ch ...[color=blue]
    >I can't send a mail with the following mail header:
    > $headers = "MIME-Version: 1.0\n";
    > $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    > $headers .= "From: \"User\" &lt;user@inter. net&gt;\n";
    >
    > Therefore $headers is set to (echo $header;)
    > MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 From:
    > "User" <user@inter.net >
    >
    > The mail has not been delivered and my PHP server says:
    > [24-Nov-2005 00:37:19] PHP Warning: mail() [<a
    > href='function. mail'>function. mail</a>]: SMTP server response: 501 5.5.4
    > Invalid Address in C:\PHP\file.php on line 132
    >
    >
    > If I use
    > $headers .= "From: user@inter.net\n";
    > instead of
    > $headers .= "From: \"User\" &lt;user@inter. net&gt;\n";
    > is works perfect.
    >
    > What's wrong?
    > Stefan
    >
    >[/color]


    Comment

    • Stefan Mueller

      #3
      Re: Why can't I send a mail with PHP

      [color=blue][color=green]
      >> If I use
      >> $headers .= "From: user@inter.net\n";
      >> instead of
      >> $headers .= "From: \"User\" &lt;user@inter. net&gt;\n";
      >> is works perfect.
      >>
      >> What's wrong?
      >> Stefan[/color]
      >[/color]

      I tried the following versions before
      $headers .= "From: \"User\" <user@inter.net >";
      or
      $headers .= "From: 'User' <user@inter.net >";
      or
      $headers .= "From: User <user@inter.net >";
      or
      $headers .= 'From: "User" <user@inter.net >';

      However, no version works.

      Does someone see what's wrong?
      Stefan


      Comment

      • Gordon Burditt

        #4
        Re: Why can't I send a mail with PHP

        >>> If I use[color=blue][color=green][color=darkred]
        >>> $headers .= "From: user@inter.net\n";
        >>> instead of
        >>> $headers .= "From: \"User\" &lt;user@inter. net&gt;\n";
        >>> is works perfect.
        >>>
        >>> What's wrong?
        >>> Stefan[/color]
        >>[/color]
        >
        >I tried the following versions before
        > $headers .= "From: \"User\" <user@inter.net >";
        >or
        > $headers .= "From: 'User' <user@inter.net >";
        >or
        > $headers .= "From: User <user@inter.net >";
        >or
        > $headers .= 'From: "User" <user@inter.net >';
        >
        >However, no version works.
        >
        >Does someone see what's wrong?[/color]

        If you don't put a newline at the end of the header, another header
        is going to wind up on the same line, and it will break things:

        From: User <user@inter.net >Subject: this is not spam

        Also, if the envelope-from and/or destination address is not valid,
        the mail won't go either, regardless of headers. No HTML allowed
        in those, either.

        Gordon L. Burditt

        Comment

        • SC

          #5
          Re: Why can't I send a mail with PHP

          Here's an example of proper headers:

          $mail_headers = 'From: "Sender Name" <sender@domain. com>' . "\n"
          .. 'MIME-Version: 1.0' . "\n"
          .. 'Message-ID: <' . md5(uniqid(time ())) . '@domain.com>' . "\n"
          .. 'Content-Type: text/html; charset="iso-8859-1"' . "\n"
          .. 'Content-Transfer-Encoding: 8bit' . "\n"
          .. 'Importance: Normal' . "\n";



          "Stefan Mueller" <seekware-remove-@yahoo.com> wrote in message
          news:dm3386$1ej o$1@news.imp.ch ...[color=blue]
          >[color=green][color=darkred]
          >>> If I use
          >>> $headers .= "From: user@inter.net\n";
          >>> instead of
          >>> $headers .= "From: \"User\" &lt;user@inter. net&gt;\n";
          >>> is works perfect.
          >>>
          >>> What's wrong?
          >>> Stefan[/color]
          >>[/color]
          >
          > I tried the following versions before
          > $headers .= "From: \"User\" <user@inter.net >";
          > or
          > $headers .= "From: 'User' <user@inter.net >";
          > or
          > $headers .= "From: User <user@inter.net >";
          > or
          > $headers .= 'From: "User" <user@inter.net >';
          >
          > However, no version works.
          >
          > Does someone see what's wrong?
          > Stefan
          >
          >[/color]


          Comment

          • Stefan Mueller

            #6
            Re: Why can't I send a mail with PHP

            > $mail_headers = 'From: "Sender Name" <sender@domain. com>' . "\n"[color=blue]
            > . 'MIME-Version: 1.0' . "\n"
            > . 'Message-ID: <' . md5(uniqid(time ())) . '@domain.com>' . "\n"
            > . 'Content-Type: text/html; charset="iso-8859-1"' . "\n"
            > . 'Content-Transfer-Encoding: 8bit' . "\n"
            > . 'Importance: Normal' . "\n";[/color]

            It's really unbelievable. I've tried so many headers and
            'From: "Sender Name" <sender@domain. com>'
            never works.
            That same with your header. PHP says:
            [24-Nov-2005 08:00:05] PHP Warning: mail() [<a
            href='function. mail'>function. mail</a>]: SMTP server response: 501 5.5.4
            Invalid Address in C:\PHP\file.php on line 132

            If I modify your header to
            $jt = 'From: sender@domain.c om' . "\n"
            . 'MIME-Version: 1.0' . "\n"
            . 'Message-ID: <' . md5(uniqid(time ())) . '@domain.com>' . "\n"
            . 'Content-Type: text/html; charset="iso-8859-1"' . "\n"
            . 'Content-Transfer-Encoding: 8bit' . "\n"
            . 'Importance: Normal' . "\n";
            it works perfect again.

            But why is
            'From: "Sender Name" <sender@domain. com>'
            never working.

            I'm trying since several days and I'm really loosing hope.
            Stefan



            Comment

            • hebiryu@gmail.com

              #7
              Re: Why can't I send a mail with PHP

              i don't really have time to analyze your code. I send you my email
              script. and my code
              is completely working. i hope it helps for you.


              *************** *************** *************** ********
              $to = $remail; // fill your email address here
              $subject = "Invitation to Patra Friends"; // fill your subject here..
              //and the message here..
              $message = "

              Kami mengundang Anda untuk menjadi member
              jaringan alumni Himpunan Teknik Perminyakan ITB

              silahkan klik
              http://alumni.tm.itb.a c.id/registrasi.php? p=$passp&q=$pas s2
              untuk melakukan registrasi

              Terimakasih
              Admin Patra -- admin@alumni.tm .itb.ac.id

              ";

              $headers .= 'From: *Patra Admin <admin@alumni.t m.itb.ac.id>' .
              "\r\n";// this one is to indicate the header..

              mail($to, $subject, $message, $headers);// this is the command

              Comment

              • SC

                #8
                Re: Why can't I send a mail with PHP

                After a little checking I found that many people report that PHP for Windows
                does not support the "from" header being anything other than just the e-mail
                address.

                You apparently can't send a "from" header like 'From: "Sender Name"
                <sender@domain. com' under PHP for Windows. This only seems to work with
                non-Windows installations of PHP.


                "Stefan Mueller" <seekware-remove-@yahoo.com> wrote in message
                news:dm3ott$1ll n$1@news.imp.ch ...
                [color=blue]
                > It's really unbelievable. I've tried so many headers and
                > 'From: "Sender Name" <sender@domain. com>'
                > never works.
                > That same with your header. PHP says:
                > [24-Nov-2005 08:00:05] PHP Warning: mail() [<a
                > href='function. mail'>function. mail</a>]: SMTP server response: 501 5.5.4
                > Invalid Address in C:\PHP\file.php on line 132
                >[/color]


                Comment

                • Stefan Mueller

                  #9
                  Re: Why can't I send a mail with PHP

                  "SC" <no_spam@thank. you> wrote in message
                  news:jvhhf.3$t6 3.220@news.uswe st.net...[color=blue]
                  > After a little checking I found that many people report that PHP for
                  > Windows does not support the "from" header being anything other than just
                  > the e-mail address.
                  >
                  > You apparently can't send a "from" header like 'From: "Sender Name"
                  > <sender@domain. com' under PHP for Windows. This only seems to work with
                  > non-Windows installations of PHP.[/color]

                  Wow, that's very bad. But now I know why I could read so many PHP mail pages
                  and it still doesn't work because it's not implemented in my PHP version.
                  That's a really very bad news. But now I know that I can stop testing and
                  testing and testing ...

                  Thanks a lot for telling me that.
                  I was really loosing the hope.
                  Stefan


                  Comment

                  Working...