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.

cant send mail using mail()function

Discussion in 'E-mail Discussions' started by ullalla, Dec 18, 2006.

  1. ullalla

    ullalla Well-Known Member

    Joined:
    Jan 20, 2006
    Messages:
    192
    Likes Received:
    0
    Trophy Points:
    16
    I am trying to send mails to yahoo and gmail to from my site but the mails are not delivered.And if I use the test account from my site then it is delivered. The script I am using as:
    <?php
    $to = "frreehost@gmail.com";
    $fromname = "test@mydomain.com";
    $subject = "Testing EMail";
    $mailheaders ="From: test <test@mydomain.com> \n";
    $msg = "This is a test message from test.\n";
    mail($to, $subject, $msg, $mailheaders);
    echo "Done!";
    ?>


    Please let me know if there is anything wrong.
     
  2. Zion Ahead

    Zion Ahead Well-Known Member

    Joined:
    Nov 10, 2006
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    Same problem here...

    Using php 4.4.4 (phpsuexed NOT enabled)
    disabled "Prevent the user "nobody" from sending out mail"

    Using Chirp's EXIM ACL

    How do I correct this?
     
  3. aralis

    aralis Member

    Joined:
    Dec 22, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Lubbock TX
    I was going to suggest disabling "Prevent the user "nobody" from sending out mail" via WHM for ullalla. Are you sure that your problem is not related to the EXIM ACL you are running? Have you tried it before you installed the ACL?
     
  4. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Assuming mail() is not in the disable_functions list in PHP.INI,
    you are lacking 1 additional parameter to your mail function ...

    Code:
    mail($to, $subject, $msg, $mailheaders, "-f $fromname");
    Many of the large email services automatically filter out messages sent
    from user "nobody" assuming those messages to be spam.

    It would also be a good idea to add an SPF record to your domain DNS record
    if you don't already have an SPF record.
     
  5. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,384
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    What do the exim logs show when you attempt to send a message in this fashion? Adding the -f flag is optional, but if you are running PHP as an Apache module, then some hosts may reject the message because the envelope sender will be nobody@hostname.tld and some e-mail providers block this. Really the only course of action you have is to check the exim logs and see what it says. If it shows the message as being sent and delivered, but it still does not arrive at the destination's mailbox, then there's likely some type of filtering being done at the destination server after the message is accepted. The administrators of the destination server would be the only ones that could investigate that.

    One other thing I see:

    PHP:
    $mailheaders ="From: test <test@mydomain.com> \n";
    There appears to be a space between the > and the carriage return. Have you tried removing that and see if that helps. I'm not sure if that would cause any problems or not. I've always used \r\n as the carriage return for additional headers. I'm not sure if that is necessary or not, but its what I normally use.

    PHP:
    $mailheaders ="From: test <test@mydomain.com>\r\n";
     
  6. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Congratulations! You just said WHY they should actually use the "-f" flag!

    Many mail service providers will broadly block "nobody@" or "root@" when sent using mail()
    without the "-f" flag but will go ahead and allow the messages if you use that parameter.

    Personally though, I would use SuPHP and then it's not an issue at all anymore! ;)


    PS: Yes, you are correct on the carriage returns. All scripts should use "\r\n" for mail carriage returns.
     
    #6 Spiral, Dec 26, 2006
    Last edited: Dec 26, 2006
  7. Zion Ahead

    Zion Ahead Well-Known Member

    Joined:
    Nov 10, 2006
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    It appears that

    /home/user/public_html/cgi-bin/ FormMail.cgi

    is calling /usr/sbin/sendmail -i -t as the mailprog.

    However when executing sendmail at the command line, we're getting a segmentation fault and core dump.

    root@server [/home/user/public_html/cgi-bin]# /usr/sbin/sendmail -i -t
    Segmentation fault (core dumped)

    root@server [/etc/mail]# ls -al
    total 16
    drwxr-xr-x 3 root root 4096 Dec 14 15:28 ./
    drwxr-xr-x 60 root root 8192 Dec 26 15:33 ../
    drwxr-xr-x 2 root root 4096 Dec 14 15:28 spamassassin/

    Can someone please explain the fix for this?
     
  8. xprt5

    xprt5 Well-Known Member

    Joined:
    Apr 6, 2003
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Houston
    rename /usr/sbin/sendmail to /usr/sbin/old-sendmail and run /scripts/eximup --force

    eximup will replace the sendmail binary with the correct one that will work.
     
  9. codegirl42

    codegirl42 Well-Known Member

    Joined:
    Mar 9, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    I have the "Prevent user nobody from sending mail...."....

    Is this the reason why "Email All Users" doesnt work in WHM?

    And if so, is there a work around for Email All Users?
     
  10. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    You can only use the "prevent user nobody" option if you have setup phpSuExec or SuPHP ...

    Otherwise, you just effectively disabled the mail function for all web scripts because
    servers not running phpSuExec or SuPHP will execute all scripts as user "nobody"!
     
Loading...

Share This Page