function mail(): error "SMTP server response: 501 #5.1.1 bad address"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bonski
    New Member
    • Jun 2007
    • 53

    function mail(): error "SMTP server response: 501 #5.1.1 bad address"

    hello everybody.. i just want to know what this error means...

    Error: mail() [function.mail]: SMTP server response: 501 #5.1.1 bad address


    the smtp set up was correct.. valid emails... and port. so im just wondering why this error still occurs.

    looking forward for your suggestions.. thanks!
  • Purple
    Recognized Expert Contributor
    • May 2007
    • 404

    #2
    Hi bonski and welcome to TSDN,

    If you take a look at the rfc defining SMTP codes here you will see the error you are getting described as:

    Code:
    5.X.X   Permanent Failure
    
           A permanent failure is one which is not likely to be resolved by
           resending the message in the current form.  Some change to the
           message or the destination must be made for successful delivery.
    and

    Code:
     X.1.X   Addressing Status
    
              The address status reports on the originator or destination
              address.  It may include address syntax or validity.  These
              errors can generally be corrected by the sender and retried.
    and

    Code:
         X.1.1   Bad destination mailbox address
    
              The mailbox specified in the address does not exist.  For
              Internet mail names, this means the address portion to the
              left of the "@" sign is invalid.  This code is only useful
              for permanent failures.
    so it looks like the mailbox you are sending to is not correct...

    Post the code doing the mail send, lets take a look at that..

    Regards

    Purple
    Last edited by Purple; Jun 15 '07, 08:27 AM. Reason: .

    Comment

    • bonski
      New Member
      • Jun 2007
      • 53

      #3
      thanks purple.. ok.. here are the codes..


      the values are just for dummies.. ^__^

      [code=php]
      //generate_newlet ter.php

      $firstname = 'firstname';
      $lastname = 'lastname';
      $sendlog_messag e = 'message here';

      $receiver_name = $firstname." ".$lastname ;

      $receiver_email 1='k_bonbon_h5@ yahoo.com';
      $receiver_email 2='';

      $sender_name = 'me';
      $sender_email = 'me@ourdomain.c om';
      $Cc_email=$rece iver_email2;
      $Bcc_email="";

      $subject = 'test';

      //this line.. opens our mail template...
      $message_arr = file('crm_templ ate/sample.htm');

      $msg = '';
      foreach ($message_arr as $line_num => $line) {
      while (preg_match("/(฿)([\w]+)/i", $line, $found_var)) { // loop when found "@" in that line ($line)
      // ........(ß).... .find the character when begin with "ß"
      // .......([w]+)/i......(......) set of sub pattern
      // ............... ..........[\w] mean find word (can be combine of charactor +number)
      // ............... ...........+ mean [w] can be more than one character
      // ............... ............i (after "/") mean to match with case-sensitive
      $temp_var=$$fou nd_var[2];
      $line=ereg_repl ace($found_var[0],$temp_var,$lin e);

      } // end while (preg_match (...
      $msg.= $line;
      }// end foreach

      include('send_e mail.php');


      the other page where na mail function is location.. here it is..

      //send_email.php

      $to = $sender_email;

      $header = "From: \"".addslashes( $sender_name)." \" <".$sender_emai l.">\r\n";
      if (isset($Cc_emai l)){
      $header .= "Cc: ".$Cc_email."\r \n";
      }
      if (isset($Bcc_ema il)){
      $header .= "Bcc: ".$Bcc_email."\ r\n";
      }

      $header .= "Reply-To: ".$to."\r\n ";
      $header .= "Content-Type: text/html; charset=TIS-620 \n";
      $header .= "MIME-Version: 1.0 \r\n";

      //in this line.. this is our smtp server... i dont know whats wrong with this.. but it works on outlook... ^__^
      ini_set('SMTP', 'mail.asianet.c o.th');

      //so this is where the problem is...
      if(mail("\"".$r eceiver_name."\ " <".$receiver_em ail1.">", $subject, $msg, $header)){
      echo 'SENT!!!!';
      }else{
      echo 'FAILED!!!!';
      }
      [/code]

      thanks.. just inform me if there's something not right with these codes...
      Last edited by Atli; Jun 27 '07, 09:58 AM. Reason: Added code tags

      Comment

      • Purple
        Recognized Expert Contributor
        • May 2007
        • 404

        #4
        Hi Bonski,

        That was interesting.. I think there were a couple of issues in there.. one is still unresolved.. try this as a working half way house:

        send_email.php

        [PHP]<?php
        //the other page where na mail function is location.. here it is..

        //send_email.php

        $to = $sender_email;

        $header = "From: \"".addslashes( $sender_name)." \" <".$sender_emai l.">\r\n";
        if (isset($Cc_emai l) and $Cc_email <> ""){
        $header .= "Cc: ".$Cc_email."\r \n";
        }
        if (isset($Bcc_ema il) and $Bcc_email <> ""){
        $header .= "Bcc: ".$Bcc_email."\ r\n";
        }

        $header .= "Reply-To: ".$to."\r\n ";
        $header .= "Content-Type: text/html; charset=TIS-620 \r\n";
        $header .= "MIME-Version: 1.0 \r\n";

        //in this line.. this is our smtp server... i dont know whats wrong with this.. but it works on outlook... ^__^
        ini_set('SMTP', 'sbs-server');
        echo "here =>".$receiver_e mail1."<= here";
        echo "here =>".$header."< = here";
        //so this is where the problem is...
        //if(mail("\"".$r eceiver_name."\ " <".$receiver_em ail1.">", $subject, $msg, $header)){
        if (mail($receiver _email1.">", $subject, $msg, $header)) {
        echo 'SENT!!!!';
        }else{
        echo 'FAILED!!!!';
        }
        ?>[/PHP]

        the headers were being malformed cause the isset check was passed but the variables were actually == ""

        the name element prefix to the email address on the mail() function isn't working for me - I pass it back to you to have a play..

        Let me know how you get on..

        Regards Purple
        Last edited by Purple; Jun 15 '07, 09:54 AM. Reason: bolding in code didn't work

        Comment

        • bonski
          New Member
          • Jun 2007
          • 53

          #5
          ei purple..

          ok.. i think the problem was not with the $header variable.. because it was just concatenating the values... ok.. here's why..

          i tried to create another page... without too much variables..

          //test_mail.php
          [PHP]
          $header = "From: kris <kristian@atpth ailand.com>\r\n ";
          $header .= "Cc: skimmerboi@gmai l.com\r\n";
          $header .= "Bcc: \r\n";
          $header .= "Reply-To: kristian@atptha iland.com\r\n";
          $header .= "Content-Type: text/html; charset=TIS-620 \n";
          $header .= "MIME-Version: 1.0 \r\n";

          echo $header;//here i display the $header.. there nothing wrong..

          ini_set('SMTP', 'mail.asianet.c o.th');

          if(mail("me <k_bonbon_h5@ya hoo.com>", "test", "message here", $header)){
          echo 'SENT!!!!';
          }else{
          echo 'FAILED!!!!';
          }
          [/PHP]

          so i had this short code.. still the same result.. uhmmm.. about the code.. 5.x.x means permanent failure.. im just wondering if there's any alternative solution for that.. or.. what's the best solution with that?

          thanks again purple..^___^

          Comment

          • Purple
            Recognized Expert Contributor
            • May 2007
            • 404

            #6
            Hi,

            I suggest you try changing:

            [PHP]mail("me <k_bonbon_h5@ya hoo.com>", "test", "message here", $header)[/PHP]

            to

            [PHP]mail("k_bonbon_ h5@yahoo.com", "test", "message here", $header))[/PHP]

            that will work

            Purple

            Comment

            • Purple
              Recognized Expert Contributor
              • May 2007
              • 404

              #7
              Hi,

              I have done a little reading on this - even got a book out !!

              It would appear some MTA's don't support extended address or are rstricted in what the will support - I suspect this is the issue we are experiencing with your to format.

              Regards Purple

              Comment

              • bonski
                New Member
                • Jun 2007
                • 53

                #8
                hahaha.. what a crazy afternoon... ok

                so now.. what i did, i follow your suggestion and also i took out the $header variable from the mail() function... and IT WORKS... thanks man...

                here it is

                [PHP]
                $header = "From: kris <kristian@atpth ailand.com>\r\n ";
                $header .= "Cc: skimmerboi@gmai l.com\r\n";
                $header .= "Bcc: \r\n";
                $header .= "Reply-To: kristian@atptha iland.com\r\n";
                $header .= "Content-Type: text/html; charset=TIS-620 \n";
                $header .= "MIME-Version: 1.0 \r\n";
                echo $header;
                ini_set('SMTP', 'mail.asianet.c o.th');
                if(mail("k_bonbon_ h5@yahoo.com", "test", "message here")){
                echo 'SENT!!!!';
                }else{
                echo 'FAILED!!!!';
                }
                [/PHP]


                uhmmm.. its really confusing.. coz the last time i used this code.. it was working.. coz i was trying to send html contents... so if i took this code out..

                $header = "From: kris <kristian@atpth ailand.com>\r\n ";
                $header .= "Cc: skimmerboi@gmai l.com\r\n";
                $header .= "Bcc: \r\n";
                $header .= "Reply-To: kristian@atptha iland.com\r\n";
                $header .= "Content-Type: text/html; charset=TIS-620 \n";
                $header .= "MIME-Version: 1.0 \r\n";

                how am i suppose to generate html contents on email.. i mean is there something wrong with this headers?

                purple.. thank you so much for your time.. i really appreciate it.. ^__^..

                Comment

                • Purple
                  Recognized Expert Contributor
                  • May 2007
                  • 404

                  #9
                  Hi Bonski,

                  I am pleased you have it working..

                  as an aside if you haven't already, take a look at this.

                  sending text or HTML as the message body should make no difference.

                  Regards Purple

                  Comment

                  • bonski
                    New Member
                    • Jun 2007
                    • 53

                    #10
                    ei purple
                    thank you so much man..

                    and thanks also for the link you gave me about errors.. i knew about mysql_error().. but the error_reporting () is kinda new to me.. and i'd been looking for something like that since morning.. so that i could track down whats wrong.. so thank you so much..

                    take care always..^__^..

                    Comment

                    Working...