Mail Function Problem.. Not sending. Any Ideas?

Discussion in 'PHP' started by -bank-, Apr 9, 2013.

  1. #1
    I've build an online form, and just need to email it, although I am receiving nothing. Any ideas for getting it working?
    $message = "Hello";
            $headers = "From: Direct Debit Form <info@website.com>\r\n";
            $headers .= "Reply-To: info@poshpads.com\r\n";
            $headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: text/html";
            $subject = "Direct Debit form for ".$_POST['account1']." ".$_POST['account2'];
            $to = "Direct Debit<dd@website.com>";
            mail($to, $subject, $message, $headers);
            $message = "<div>Your Direct Debit Details have successfully been sent, please print a copy for your own records:</div>";
    PHP:
    Thank you!
     
    -bank-, Apr 9, 2013 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    I think $to needs to be defined as just an address?

    $to = "info@website.com";
    $from = "dd@website.com";
     
    $subject = "Direct Debit form for ".$_POST['account1']." ".$_POST['account2'];
     
    $message = "<div>Your Direct Debit Details have successfully been sent, please print a copy for your own records:</div>";
     
    $headers = "From: Direct Debit Form :" . $from;
     
    $headers .= "Reply-To: info@poshpads.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html";
    mail($to,$subject,$message,$headers);
    Code (markup):
     
    MyVodaFone, Apr 9, 2013 IP
    -bank- likes this.
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    The $to can be anything that complies with the http://www.faqs.org/rfcs/rfc2822.html rules.
    Chances are you are on windows (in which case you don't have sendmail installed). This usually works out of the box on Linux systems.
     
    ThePHPMaster, Apr 9, 2013 IP
    -bank- and MyVodaFone like this.
  4. -bank-

    -bank- Well-Known Member

    Messages:
    674
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    120
    #4
    I have made the changes, code is now:
    
    $message = 'Hello';
    $headers = "From: info@yourserver.com\r\n";
    $headers .= "Reply-To: info@yourserver.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html";
    $subject = "Direct Debit form for ".$_POST['account1']." ".$_POST['account2'];
    $to = "dd@yourserver.com";
    mail($to, $subject, $message, $headers);
    PHP:
    Originally it was on a windows box, although I have just moved to a linux host and still no success.
    Thanks for all the help!
     
    -bank-, Apr 10, 2013 IP
  5. -bank-

    -bank- Well-Known Member

    Messages:
    674
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Thanks tube ace, I have just tried the code, adjusted, to include valid emails, although nothing is being sent / received. I'll get in touch with the host. Thanks
     
    -bank-, Apr 10, 2013 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    Have you checked that the mail function is enabled on your host? Add this to a script and see if it's in the information.

    
    echo phpinfo();
    
    PHP:
    Another thing is make sure that error reporting is on full to let you know if there's any problems. Place this code above the script.

    
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    
    PHP:
     
    HuggyStudios, Apr 10, 2013 IP
  7. Alex Raven

    Alex Raven Greenhorn

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #7
    Is sendmail (or other mail transfer program, such as exim, postfix) set up correctly on the server? Try this first:

    <?php
    $result = mail("you@domain.com", "test subject", "test message");
    if ($result) echo "Email OK"; else echo "ERROR";
    ?>
    Code (markup):
    If the above code says ERROR, you may have non working email server. You can also try phpmailer which is capable to send HTML emails, and use mail(), sendmail directly and SMTP (local or external).

    http://phpmailer.worxware.com/
     
    Alex Raven, Apr 18, 2013 IP