php mail() sent as [email protected]

Discussion in 'Installation/Configuration' started by bwragg, Feb 26, 2007.

  1. bwragg

    bwragg New Member

    if I do the following in a php page

    Code:
    if (mail($ADDR,"Testing","This is a test"))
    the mail gets sent from [email protected]. I assume this is happneing becuase the httpd server is running as the apache user? Is there any way to stop this so that the email is sent automatically from the domain the page is being run in?

    I know you can add the $header parameter to the mail function with a "From:" statement in it, but is there anyother way.

    Thanks,

    Ben
     
  2. Ben

    Ben ISPConfig Developer ISPConfig Developer

  3. bwragg

    bwragg New Member

  4. edge

    edge Active Member Moderator

    If you add a "from" email address in the PHP mail() , it will use that instead of the [email protected]
    You will need to add it in the "headers"

    Code:
    <?php
    $to = "[email protected]";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "[email protected]";
    $headers = "From: $from";
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
    ?>
    
     
    Last edited: Feb 26, 2007
  5. bwragg

    bwragg New Member

    That works great, Thanks.

    Is the reason its being sent by apache due to the fact that apache is the user that is running php?

    If I setup my system differently so that php was running using something like suphp would the email go out via the owner of the file rather than the apache user?

    Thanks,

    Benjamin
     
  6. Ben

    Ben ISPConfig Developer ISPConfig Developer

    If you set the Header From, just remember that this is only the X-Header, i mean it is never the less displayed in the email riht, but in the header you can see the "original" E-mailadress anyway, just fyi.
     
  7. Emile van EWeden

    Emile van EWeden New Member

    re

    I there.
    I have the same issue when sending email using php. I also tried the example by the user "edge" with no luck. What else can I try? Thank you

    Code:
    Feb 13 06:55:30 mailer postfix/qmgr[1273]: 4BB1E1D3A4: from=<[email protected]>, size=473, nrcpt=1 (queue active)
    Feb 13 06:55:33 mailer postfix/smtp[2507]: 4BB1E1D3A4: to=<[email protected]>, relay=smtp.wugnet.com[221.52.0.17]:25, delay=3.8, delays=0.86/0.03/1.8/1.1, dsn=2.0.0, status=sent (250 OK id=1U5Vyp-0006Ba-G0)
    
     
  8. edge

    edge Active Member Moderator

    You can try by adding the -f option to it.

    Somtehing like this: mail($to,$subject,$message,$headers,"-f".$from);
     
  9. Emile van EWeden

    Emile van EWeden New Member

    Hi still doing the same :confused:
     
  10. Emile van EWeden

    Emile van EWeden New Member

    Hi i got it working by editing ssmtp.conf.
     

Share This Page