SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mail function failed ?

    Hi All,

    Im using using the below code to send mail from my local server.If i send mail to other servers (like gmail,yahoo) result "Success" . but ,if i send mail to server itself result "failed". why ? any one help me plz!

    Code PHP:
    <?php
    $from = "xxx.com";
    $subject = "sample";
    $message = " Orders : ".$_SESSION['details'];
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $to =$mail;
    $headers = "$from". "\r\n";
    if ($_SERVER['REQUEST_METHOD'] == "POST") {
    	foreach ($_POST as $key => $value) { 
    		$msg .= ucfirst ($key) ." : ". $value . "\n"; 
    	}
    }
    else {
    	foreach ($_GET as $key => $value) { 
    		$msg .= ucfirst ($key) ." : ". $value . "\n"; 
    	}
    }
    $sent = mail($to,$subject,$message,$headers);
    if ($sent) {
      echo " success";
     } else 
     {
      echo "failed.";
     }
    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try a simpler test
    PHP Code:
    $sent mail('email@''test''working?'); 
    There is a problem with your headers, but at least if that works then we can know the server etc is configured correctly.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    notice that $mail is undefined in your code.
    Use this code to enable the error reporting:
    PHP Code:
        error_reporting(E_ALL);
    ini_set("display_errors"1); 
    And make sure you have started the session with session_start()

  4. #4
    SitePoint Member temmokan's Avatar
    Join Date
    Dec 2009
    Location
    Novosibirsk, Russia
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To use the same server (localhost?), please make sure there's a SMTP service running on it and accepting the mail.

    Enabling PHP errors logging could certainly help a lot. Myself, I use xdebug to pinpoint PHP errors.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. I have already defined $mail var. ex:$mail=sample@domain.com,

    2. local server (mentioned above ) is not localhost, that is 74.55.xxx.xx

    3. i had declared session_start(); in my page

  6. #6
    SitePoint Member temmokan's Avatar
    Join Date
    Dec 2009
    Location
    Novosibirsk, Russia
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rsmaha View Post
    local server (mentioned above ) is not localhost, that is 74.55.xxx.xx
    Does the IP mentioned accept connections from your server? You can easily check that by using telnet:

    telnet 74.55.xxx.xx 25

    If the server accepts connections from your location, it will introduce itself. Furthermore, I usually emulate 'conversation' with SMTP server to check whether it actually accepts mail as expected:

    Code:
    [sagari@xxxxx ~]$ telnet xx.yy.zz.dd 25
    Trying xx.yy.zz.dd...
    Connected to xx.yy.zz.dd.
    Escape character is '^]'.
    220 example.com ESMTP Exim 4.63 Fri, 04 Dec 2009 02:46:20 -0800
    EHLO xxxxx
    250-example.com Hello xxxx
    250-SIZE 52428800
    250-PIPELINING
    250-STARTTLS
    250 HELP
    MAIL FROM:someone@example.net
    250 OK
    RCPT TO:someone@example.com
    250 Accepted
    DATA
    354 Enter message, ending with "." on a line by itself
    Subject: test
    From: someone@example.net
    To: someone@example.com
    Content-Type: text/plain; charset=utf-8
    
    test
    .
    250 OK id=1NGVgs-0003Ab-W7
    QUIT
    My input is in bold. The rest are server responses. Of course, you should use real-life email addresses to send to SMTP.
    Konstantin Boyandin
    Network and Server Monitoring Tool: uptime/performance monitoring

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sent = mail('email@', 'test', 'working?');

    1. i had assign if email@=xxx@mydomain.in, and i exec this from my server , im getting this error

    Warning: mail() [function.mail]: SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\Inetpub\vhosts\xxx\httpdocs\a.php on line 2


    2. if i assign mail@=xxx@yahoo.com
    no error.

  8. #8
    SitePoint Member temmokan's Avatar
    Join Date
    Dec 2009
    Location
    Novosibirsk, Russia
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rsmaha View Post
    550 Requested action not taken: mailbox unavailable or not local
    Most probable reasons are:

    1. There is no such mail address to receive mail, OR the mailbox is refusing mail - e.g., it's over quota.
    2. The mail is not local (not accepted by the sever you are connecting to) and SMTP authentication is required to relay it properly.

    I would also suggest using specialized PHP class such as phpMailer to handle mail delivery. It will provide more flexibility, functionality and error handling.
    Last edited by temmokan; Dec 4, 2009 at 03:57. Reason: typos
    Konstantin Boyandin
    Network and Server Monitoring Tool: uptime/performance monitoring

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xxx@mydomain.in
    i hav mentioned above is squirrelmail Emailid

    and plz tel me that where can i get that specialized mailer function ?

    also i have one more problem with this , is I had declared
    $from = "xxx.com";
    in my code. But when i receive that mail to my mailbox it showing someother Email-Id.

  10. #10
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing your email server is not set up correctly, ie yahoos is so that works, but yours isn't so it doesn't.

    You can find that "specialized email function" by googling, but I'd recommend swift mailer instead (also avail via google).

    The From header needs to be declared like so:
    'From: mail@domain.com'."\r\n"


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
  •