mail() messages bounce with 501 syntax error in MAIL FROM command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • paul brown

    mail() messages bounce with 501 syntax error in MAIL FROM command

    Hi,

    I have this website that contains an internal message system that allows
    users to send each other "email" messages. My client wants me to extend
    the system so that when a user receives an internal message, the system
    will send an actual email to the user's email address.

    here's the sample code:

    function notify_recipien t()
    /* Send an external email to the recipient of the internal email. */
    {
    $return = false;
    $recip = new User();
    if (strcmp($this->recipient, "") == 0 )
    {
    $this->errormessage .= "Email Recipient is Missing,";
    }
    else
    {
    $recip->userid = $this->recipient;
    $recip->load_by_id() ;
    }
    $sender = new User();
    if(strcmp($this->sender, "") == 0)
    {
    $this->errormessage .= "Email Sender Is Missing,";
    }
    else
    {
    $sender->userid = $this->sender;
    $sender->load_by_id() ;
    }
    $site = new Site();
    $site->site_id = $recip->site_id;
    $site->load_by_id() ;

    $to = $recip->email;
    $from = "<webmaster @" . strtolower( $site->site_name ) .">";
    $subject = "New Message at $site->site_name";
    $message = "Howdy, $recip->username, \r\n".
    "You have received a new message from $sender->username over at
    $site->site_name." .
    " Please visit $site->site_url to retrieve your message.\r\n\r\ n" .
    "Thanks,\r\n\r\ n" .
    "The Team at $site->site_name";

    $headers = "From: $from\r\n";
    if (mail( $to, $subject, $message, $headers))
    {
    $return = true;
    }
    return $return;
    }

    Here's the raw message it generates:

    Received: by [host obscured] (Postfix, from userid 72)
    id A684219E678; Thu, 10 Feb 2005 16:46:58 -0800 (PST)
    To: [email obscured]@yahoo.com
    Subject: New Message at LeatherM4M.net
    From: <webmaster@leat herm4m.net>
    Message-Id: <20050211004658 .A684219E678@st ud.aliceblue.or g>
    Date: Thu, 10 Feb 2005 16:46:58 -0800 (PST)



    Howdy, bigredpaul,
    You have received a new message from bigredpaul over at [site name
    obscured]. Please visit http://[url obscured]/ to retrieve your message.

    Thanks,

    The Team at [site name obscured]


    And here's the message I get back from yahoo, for instance:

    <[email obscured]@yahoo.com>: host mx1.mail.yahoo. com[67.28.113.11]
    said: 501 Syntax error in parameters or arguments (in reply to MAIL FROM
    command)


    Does anyone have any thoughts about what I might be doing wrong?

    Thanks,

    Paul
  • Senator Jay Billington Bulworth

    #2
    Re: mail() messages bounce with 501 syntax error in MAIL FROM command

    paul brown <nntp@paulbrown .net> wrote in news:ntTOd.3699 $aW6.483
    @newssvr22.news .prodigy.net:
    [color=blue]
    > Hi,
    >
    > I have this website that contains an internal message system that[/color]
    allows[color=blue]
    > users to send each other "email" messages. My client wants me to[/color]
    extend[color=blue]
    > the system so that when a user receives an internal message, the system
    > will send an actual email to the user's email address.
    >
    > here's the sample code:
    >
    > [snip]
    >
    > $headers = "From: $from\r\n";[/color]

    Remove the \r\n from that line and you should be OK. It's only necessary
    if you're sending multiple headers, e.g.

    $headers = "From: $from\r\nBcc: foo@example.com";

    [color=blue]
    > Received: by [host obscured] (Postfix, from userid 72)[/color]
    ^^^^^^^^^^^^^^^[color=blue]
    > Subject: New Message at LeatherM4M.net[/color]

    hth ;))


    --

    Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
    --------------------------|---------------------------------
    <http://www.phplabs.com/> | PHP scripts, webmaster resources

    Comment

    • paul brown

      #3
      Re: mail() messages bounce with 501 syntax error in MAIL FROM command

      Senator Jay Billington Bulworth wrote:[color=blue]
      > paul brown <nntp@paulbrown .net> wrote in news:ntTOd.3699 $aW6.483
      > @newssvr22.news .prodigy.net:
      >
      >[color=green]
      >>Hi,
      >>
      >>I have this website that contains an internal message system that[/color]
      >
      > allows
      >[color=green]
      >>users to send each other "email" messages. My client wants me to[/color]
      >
      > extend
      >[color=green]
      >>the system so that when a user receives an internal message, the system
      >>will send an actual email to the user's email address.
      >>
      >>here's the sample code:
      >>
      >>[snip]
      >>
      >> $headers = "From: $from\r\n";[/color]
      >
      >
      > Remove the \r\n from that line and you should be OK. It's only necessary
      > if you're sending multiple headers, e.g.
      >
      > $headers = "From: $from\r\nBcc: foo@example.com";
      >[/color]

      It doesn't matter whether or not they exist or not. I've tried it with
      and without.

      Thanks though,

      Paul

      Comment

      • Alvaro G Vicario

        #4
        Re: mail() messages bounce with 501 syntax error in MAIL FROM command

        *** paul brown wrote/escribió (Fri, 11 Feb 2005 01:01:07 GMT):[color=blue]
        > if (mail( $to, $subject, $message, $headers))[/color]

        If the error is returned by the mail server, the only line in your code
        that matters is the one above. What are the actual values of the variables
        you pass as arguments?

        Hint: echo

        --
        -- Álvaro G. Vicario - Burgos, Spain
        -- Thank you for not e-mailing me your questions
        --

        Comment

        • paul brown

          #5
          Re: mail() messages bounce with 501 syntax error in MAIL FROM command

          Alvaro G Vicario wrote:[color=blue]
          > *** paul brown wrote/escribió (Fri, 11 Feb 2005 01:01:07 GMT):
          > [color=green]
          >> if (mail( $to, $subject, $message, $headers))[/color]
          >
          >
          > If the error is returned by the mail server, the only line in your code
          > that matters is the one above. What are the actual values of the variables
          > you pass as arguments?
          >
          > Hint: echo
          > [/color]

          The values are correct, so it's leading me to think that perhaps the
          problem lie in my outgoing mail server.

          Thanks,

          Paul

          Comment

          • paul brown

            #6
            Re: mail() messages bounce with 501 syntax - a solution, sort of

            paul brown wrote:[color=blue]
            > Hi,
            >
            > I have this website that contains an internal message system that allows
            > users to send each other "email" messages. My client wants me to extend
            > the system so that when a user receives an internal message, the system
            > will send an actual email to the user's email address.
            >[/color]

            I ended up using an open source group of classes called PHPMailer, and
            its companion SMTP class. While that Postfix server works just fine for
            every other type of mail, sending via mail() wasn't cutting it, but the
            PHPMailer and SMTP objects work just fine.

            Thanks to everyone who suggested things,

            Paul

            Comment

            Working...