The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP mail() function return problem

Discussion in 'E-mail Discussions' started by MrMagoo, Jan 30, 2006.

  1. MrMagoo

    MrMagoo Member

    Joined:
    Sep 6, 2005
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    I have a client who is experiencing problems with PHP mail() function returns. Currently all mail sent via sendmail is returning TRUE, regardless if the email address is invalid. Why would this be happening?

    I have had my client provide me with the headers they are using below:

    $return = mail("functional@emailaddress.com","test","test"); print $return ? "TRUE" : "FALSE"; # TRUE is expected

    $return = mail("test@test.test","test","test"); print $return ? "TRUE" : "FALSE"; # FALSE is expected
     
  2. neo4242002

    neo4242002 Well-Known Member

    Joined:
    Jun 28, 2005
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Are you reseller or dedicated user?

    If you have complied php as an apache module, cpanel forward all undeliverable mails according to the email addresses in Main >> Server Contacts >> Change System Mail Preferences.

    So every time you are using an invalid email address, you are sys admin will receive an email with following subject line "Mail delivery failed: returning message to sender"

    Another thing to do is enable "Verify the existence of email senders." (Extra spam protection) on WHM root and change your script something like bellow

    PHP:
    $returnemail should be a valid email addressperhaps the default website address.

    mail($to$subject$message$headers"-f $returnemail");
    Hope this help you bit but also Google for "email ejection" to learn the safety guides for your php mail functions :)
     
  3. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    The purpose of the mail() function is to send mail-destined data on to sendmail (or an appropriate wrapper). If it does so successfully, it will return true, otherwise it will return false.

    As you can see, this has no bearing on the validity of the data. Although uncommon, you could have an email address or user@hostname that could operate perfectly well within a local network environment.

    It is therefore the responsibility of the PHP developer, and not PHP, to ensure data validity.
     
  4. MrMagoo

    MrMagoo Member

    Joined:
    Sep 6, 2005
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    So can I assume from what you're saying that the PHP mail() function cannot return a TRUE if an email has been successfully delivered to it's intended recipient? The return functions are just internal if you like, acknowledging if it has parsed to sendmail ??? If so, is there any way to confirm a successful delivery to the outside?
     
  5. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    Absolutely, your explanation is spot on.

    I doubt that it would be possible to confirm a successful delivery to the outside and I'll explain why.

    Let's imagine an email being sent through PHP. It would (very roughly) go something like this:

    1. PHP passes mail to sendmail (or equivalent wrapper)
    2. Mail gets passed on to and sent out by Exim
    3. Mail gets sent through an indeterminable amount of MTAs
    4. Mail reaches recipient mailbox

    The best that could possibly be done would be for Exim to return something back to the sendmail wrapper, which in turn would pass something back to PHP, saying that the email left the server. But that by no means means that the email will actually get anywhere.

    You have to remember that email is an asynchoronous data transfer process - once sent you have no idea if it will reach the recipient or when.

    In short, no, I don't think it's possible for PHP to confirm a successful delivery to the outside. If it could, I don't doubt that it already would!
     
  6. MrMagoo

    MrMagoo Member

    Joined:
    Sep 6, 2005
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    Thank you webignition, that all makes a lot more sense to me now. I'm off to try and explain to my client it can't be done like they thought it could. Cheers. :)
     
Loading...

Share This Page