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.

mail() funtion in php not sending email, not producing error

Discussion in 'E-mail Discussions' started by SharonGilmore, May 6, 2011.

  1. SharonGilmore

    SharonGilmore Member

    Joined:
    May 5, 2011
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    I'm trying to get my app to send an email. I have the following code, as a test:

    function sendTestEmail() {
    $to = 'myemailaddress@gmail.com';
    $subject = "Share your page with the world!";
    $body = "This is a test message\n\n";
    $headers = 'From: no-reply@pubfish.com' . "\r\n" .
    'Reply-To: no-reply@pubfish.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    if (mail($to, $subject, $body, $headers)) echo 'Sent';
    else echo 'Error';
    exit();
    }

    When I run it, it completes fine, and echoes 'Sent'. However, the email never arrives. I've searched online, and most people who've come across this seem to have fixed it by changing "Prevent “nobody” from sending mail" to 'off'. I tried that, and it was already off.

    I didn't set up the server, someone else did - I can't contact him directly, so I'd like to be able to figure this out myself (also so I would know how it works). I don't know if anything was set up for emailing. I haven't mentioned email settings anywhere in my code, as I don't know whether I need to. I'm kind of new to this sort of thing.

    I'd be really grateful for any pointers anyone can give me. What kinds of settings etc should I be checking?

    Thanks!
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Have you checked the exim logs for any information?

    Code:
    exigrep myemailaddress@gmail.com /var/log/exim_mainlog
    Also, how are you testing the script? Are you doing it via command line to run the script or using a browser?
     
  3. SharonGilmore

    SharonGilmore Member

    Joined:
    May 5, 2011
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    Hi, thanks for your reply.

    I've been testing in the browser (I haven't set up command line access yet). I can't find the exim logs - var isn't listed when I click on File Manager, and I looked round but couldn't see it anywhere else. Can you point me in the right direction?

    Thanks again.
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    You would need to have root SSH access to the machine to view the exim logs. All of the main server logs are unavailable in File Manager for cPanel accounts and only available for the root level user in SSH.

    If you do not have root access to the machine, you would need to contact your hosting provider for assistance with this issue.
     
  5. SharonGilmore

    SharonGilmore Member

    Joined:
    May 5, 2011
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    Thanks again for your reply. I've logged in as root, and checked the exim_mainlog file. There's quite a lot in there, and I'm not sure what's relevant.

    The first bit is:

    I've no idea what any of this means! Can anyone help me out?

    Thanks!
     
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Did you check the exim logs with the command I provided? The full logs won't be very meaningful, which is why you would exigrep for the exact email account:

    Code:
    exigrep myemailaddress@gmail.com /var/log/exim_mainlog
    This is the previously provided command you would use. You would replace myemailaddress@gmail.com with the real gmail address being used to send to from the script.
     
  7. jammer699669

    jammer699669 Registered

    Joined:
    Jul 1, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    I have the same iissue

    2011-07-01 20:25:50 1Qcpu2-0000xx-HF <= general@spangaloo.com U=spang P=local S=572
    2011-07-01 20:25:50 1Qcpu2-0000xx-HF => jamesb <jamesb@jambux.com> R=virtual_user T=virtual_userdelivery
    2011-07-01 20:25:50 1Qcpu2-0000xx-HF Completed


    that tells me it was sent but it never arrives

    this also happens when I send from a script and the destination is on the same server

    the list above is from using this
    exigrep myemailaddress@gmail.com /var/log/exim_mainlog

    I used Putty to access the server
    I have check the Nobody setting as well and it is set to off etc
    this is making me insane because I have
    2 servers running identical same Cpanel and WHM one sends mail and one does not
    This seems to be a recent event that it stopped working on the one server because it used to work
     
    #7 jammer699669, Jul 1, 2011
    Last edited: Jul 1, 2011
  8. nixell

    nixell Active Member

    Joined:
    Sep 24, 2007
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    I have same problem, but there no log even using exigrep. not all account can't send email
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    It's difficult to pinpoint this to any specific error or configuration without access to the server. I suggest opening a support ticket so we can check further:

    Submit A Ticket

    You can post the ticket number here so we can share the solution when it's resolved.

    Thank you.
     
  10. jloughran

    jloughran Registered

    Joined:
    Mar 1, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    DataCenter Provider
    We had a similar issue on our cPanel server but we figured it out. Our circumstances may be different, so let me explain:

    We discovered that the php mail() function would not send mail unless the user's mail routing settings were set to 'Remote Mail Exchanger'. We do not use the cPanel mail server but a separate hosted system. After setting that for the user, it function worked fine. 'Automatically Detect Configuration' does not work.

    Not sure if you are using the cPanel mail or not, or if this applies to your situation. Right now I am in the process of trying to figure out how to change the mail routing setting by script (if it is possible) and ran across this thread. We provision out accounts through the Platypus billing system so, as this option is not available via the package settings, nor would I know how to change the VB script to change this setting. So I thought about trying to make it change after account creation. I wish there was a way to set it globally for all new accounts. It's quite a pain to change it for every account and have users complain about why php mail() doesn't work - because who would think that changing the mail routing setting would change the behavior of php mail()? If anyone can lead me in the right direction it's appreciated - however I am still researching to get ready to post a new thread/feature-request.
     
  11. jloughran

    jloughran Registered

    Joined:
    Mar 1, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    DataCenter Provider
    Follow up: It does seem that Automatically Detect Configuration does allow php mail() to work. Not sure if this problem originated with early accounts we created being automatically set to 'local' routing or not. We added the IP addresses of our mail exchangers to the 'Configure Remote Service IPs' section for good measure, but it did not seem to affect the outcome one way or the other. As long as the mail routing is not set to 'local' we are OK.
     
Loading...

Share This Page