Forum Moderators: coopster

Message Too Old, No Replies

mail() Not Working

Success message, but no email comes

         

ridingforlife

3:07 am on Jan 5, 2011 (gmt 0)

10+ Year Member



Hi everyone,

I had a problem last week with this email form and though it was solved, another problem has come up that I'm stumped on.

The problem now, is that when I send the email form, the success message tells me the email has been sent - but no email comes. I tested and my validation is working, so I don't believe I am getting a false positive if you will. The PHP for this form is exactly the same as on two other websites, both of which are working fine.

I'm wondering if this could be related to the server of this website? Is there any sort of error checking I can do? Any thoughts would be great.

Thanks!

SevenCubed

3:54 am on Jan 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First thing that comes to mind for me is have you tried sending it to different email addresses or just one? Also, if the original problem isn't too extensive to explain it might help us with some background info that might give clues to your present problem.

ridingforlife

7:01 am on Jan 5, 2011 (gmt 0)

10+ Year Member



Yes, I have tried with 3 different email addresses.

The problem from last week can be found here: [webmasterworld.com...]

I'm pretty sure it is unrelated, I've gotten further after that problem was solved, but now I have this road block.

Matthew1980

9:12 am on Jan 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>The problem now, is that when I send the email form, the success message tells me the email has been sent - but no email comes. I tested and my validation is working, so I don't believe I am getting a false positive if you will.

This is one of the problems with using the mail() function, the function when invoked will return a boolean value if the function 'thinks' as it has completed it's task, it will only return false/0 if something within the function fails - at least that's my experience of it.

Generally if your function/script/class is working on one server and not another means that something in the php.ini file is different, you may need to check those settings, but before you get in touch with the grumpy IT guy (I am grumpy electronics Guy so I know how he feels! :)) check the obvious first.

  • Check that when the mail function has been accessed and success message comes through, that your email hasn't ended up in the spam folder on the recipients email address.

  • Check that everything in the headers when your constructing them is right.

  • Make sure that the email address is being entered correctly - I'm sure that's caught us all out at some point or other.

    Then go from there, and if necessary strip the mail function back to the most minimal as it works with and then progress from there.

    Lastly, check the php.ini files out, see what the differences are, I assume as your on another host where this issue arises.

    Cheers,
    MRb
  • rocknbil

    4:45 pm on Jan 5, 2011 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    First stop is your mail logs, otherwise, try this . . .

    if (mail($to, $subject, $message, $headers)) {
    //success message
    }
    else {
    header("content-type:text/html");
    echo "<p>Error . . . here is what was sent</p>";
    echo "<pre>
    To: $to
    Subj: $subject
    Message: $message
    Headers: $headers
    </pre>";
    exit;
    }

    If it still gives you success, comment out all the if/else blocks, just print it out. If it's an HTML email you may have to view source. Examining exactly what's sent to mail() may be a big help.

    Next stop: some systems won't allow a submission from the same email address as the domain, this is a common spam attack ("anything@yourdomain.com"). Try a different email address.

    ridingforlife

    3:13 am on Jan 7, 2011 (gmt 0)

    10+ Year Member



    Thanks everyone...

    I checked and the mail is not ending up in the spam folders, and the email address is correct.

    I am not using any headers. I know these are optional - do you think using them would make it work?

    It's not an HTML email... just plain text. All the information input by the user is validated and put into the body of the email.

    SevenCubed

    3:33 am on Jan 7, 2011 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    I would definitely include the headers. It will help get you a green light with many email servers, especially the Return-Path. It may or may not be your problem but is worth a try. Here is an example, you said yours is plain text so you can modify this to fit your needs:

    <?php

    $subject = "Mail Not Arriving";
    $message = "User validated input for body of the email";
    $recipient="address@example.com";
    $headers = "Return-Path: address@example.com\n";
    $headers .= "From: Example <address@example.com>\n";
    $headers .= "Reply-To: address@example.com\n";
    $headers .= 'MIME-Version: 1.0' . "\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";

    mail($recipient, $subject, $message, $headers);
    ?>

    Do you have root access to this server or is it a shared hosting plan? Has this thing worked before on this server and has now stopped working?

    ridingforlife

    6:20 am on Jan 7, 2011 (gmt 0)

    10+ Year Member



    Hmm doesn't seem to work, even with the fake addresses in the $header.

    This is an in-house server. This website is for my university's student newspaper, and they have an in-house server running to keep costs low. I can physically go to the server on campus, but I wouldn't know where to begin. I have contacted the tech guy who set up the server, and have yet to hear back.

    No, this is something new I am putting in that the newspaper wants. I'm the web editor for them for the year, and I put the articles from each bi-weekly issue online. However, servers are not my area of expertise.

    Matthew1980

    11:45 am on Jan 7, 2011 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    >>Hmm doesn't seem to work, even with the fake addresses in the $header.

    Silly as this sounds, have you got error reporting on in the script, as this may tell you what's happening, for example, if the smtp settings are set and are pointing to a valid server.

    When I am developing any script that uses mail() I always test it on my localhost that I know doesn't have any smtp settings done, and when I invoke the mail function (with error reporting on) I get an error saying that the function couldn't access valid smtp settings - thus proving that the mail() function is at least up until that point functioning and referencing external files as it needs to.

    I have a feeling that this is down to something in your php.ini file on the server that your working on, check that it has a valid server port and return address.

    This is from my own php.ini file, and should give you an idea of what your looking for:-

    [mail function]
    ; For Win32 only.
    ; h t t p://php.net/smtp
    SMTP = localhost
    ; h t t p://php.net/smtp-port
    smtp_port = 25

    ; For Win32 only.
    ; h t t p://php.net/sendmail-from
    sendmail_from = pp@yourdomain

    ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
    ; h t t p://php.net/sendmail-path
    ;sendmail_path =

    ; Force the addition of the specified parameters to be passed as extra parameters
    ; to the sendmail binary. These parameters will always replace the value of
    ; the 5th parameter to mail(), even in safe mode.
    ;mail.force_extra_parameters =

    ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
    mail.add_x_header = On

    ; Log all mail() calls including the full path of the script, line #, to address and headers
    ;mail.log =


    Check over your parameters and ensure as they are correct, if they are, then the problem lies somewhere else, but from what has been posted by SevenCubed that should act as an excellent tester, then when your monitoring your email inbox, check the spam filter, as they often end up in there.

    But honestly, having error_reporting(E_ALL|E_STRICT); turned on and used on your script, this shall inform you if there are any server issues.

    Hope this helps a little.

    Cheers,
    MRb

    ridingforlife

    7:34 pm on Jan 7, 2011 (gmt 0)

    10+ Year Member



    Thanks MRb,

    When I run the error_reporting function, it doesn't return anything. I ran phpinfo(), and under the configuration of the PHP core, it says error_reporting has no value.

    How do I access the php.ini file?

    ridingforlife

    1:52 am on Jan 9, 2011 (gmt 0)

    10+ Year Member



    I just wanted to give an update...

    I heard back for our tech guy, and apparently the problem could be because there is no email sending service on the newspaper's server. The university blocks all unregistered email servers in their network. He's going to check into this on Monday, so I should find out more next week.

    Thanks everyone for your help, and I will let you all know what the outcome is!