Results 1 to 3 of 3

Thread: PHP Mail Not Working

  1. #1
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default PHP Mail Not Working

    Code:
    PHP Code:
    $to "me@me.com";
    $subject "Question from the Fact or Fiction Forum";
    $from "you@you.com";
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $headers .= 'From: '.$from.'';

    $message '
    <html>
    <head>
      <title>Question from the Fact or Fiction Forum</title>
    </head>
    <body>
    This question is from <b>'
    .$name.'</b> with the email address <b>'.$email.'.<br>
    Here\'s the question:<br>
    '
    .$question.'<br><br>
    <a href="">Click here to answer the question.</a><br><br>
    </body>
    </html>'
    ;
    mail($to,$subject,$message,$headers); 
    This isn't sending.
    Any help would be appreciated! THANKS!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Nothing in that looks specifically wrong. Have you confirmed that mail() functions on your server?

    Try:
    mail('me@me.com','Test','Testing an automated email...');

    If that works, then something is wrong with the code above. It might be something simple or it might be a conflict with the format of the text and/or headers. I haven't looked into it much.

    But if it doesn't work, then mail() is not properly configured. It may mean you need to change a setting or it may mean that you don't have a mail server configured on the server and will need to set that up-- if you don't know how or don't have access to do so, the best answer really is to just switch hosts and use a decent host that has the basics like that setup-- it's pretty much standard.
    You can use <?php phpinfo(); ?> and look through the information given (it'll be a full page of text, so you can just use that on a new/blank page), and see if you can find something about a mail server. If so, it's probably configured so that's not the problem.


    And before you spend a lot of time trying to fix all of this, 1. be sure that you typed your email address correctly and 2. the message isn't getting sent to your spam folder instead. It's possible it'll be seen as spam because it's automated. These might seem obvious, but it's not worth putting the time in to fix the code without double-checking this.
    Also, I have heard that sometimes particular email companies/accounts just don't get emails from PHP for some reason. While I don't really believe this is a definitive answer and it can't be fixed, it's not a bad idea to try a few different emails (at a different .com, etc). If it doesn't work on 2 of your emails, then you can be pretty sure it's not working.


    Finally, the first thing in the code itself to start debugging is to figure out if PHP thinks that it's working or thinks that there was an error.
    Surround mail() with an if like this:
    PHP Code:
    if (mail(....SAME AS YOUR CODE.....)) {
    echo 
    'PHP thinks it is working';
    }
    else {
    echo 
    'PHP knows it is broken, not sure why';


    The only thing that looks suspicious in your code is that you're trying to send an html email. That should be possible, but it's something to eliminate as a possible problem while testing.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    I also had the same problem. I was using Godaddy.com and they have a special link in your hosting control panel to enable/allow php email script on your site. They do this to prevent spammers from manipulating code. I'm pretty sure it would be your host.

    Hope that helps

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •