php Mail function not working on site

Discussion in 'PHP' started by LinksMaster, Dec 12, 2008.

  1. #1
    Hello all.

    I am sure my code is correct. But this mail function is not working on my site. On this site PHP Version 5.2.6 is install. when i run this code message is appear "Mail sent successfully!". But mail not sent.

    Please any one tell why mail function is not send mail.

    Please help me



    $to = $_POST[user_name];

    $subject = 'Password Information ';

    $message = '
    <p>Your Detail</p>
    <p> text here </p>';


    // To send HTML mail, the Content-type header must be set

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: Client<mail@abc.net>' . "\r\n";


    // Mail it
    $msent=mail($to, $subject, $message, $headers);

    if(!$msent)
    {
    $error="Not Sent!";
    }
    else
    {
    $error="Mail sent successfully!";
    }

    Regards,
    Ronny
     
    LinksMaster, Dec 12, 2008 IP
  2. farad

    farad Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    change
    to
    $message = "content here";
    PHP:
    Next thing .. 3 times $header .. The same as I will say that 2 is equal to 3, 4 and 5 .. !

    Please edit your post and paste everything from your file .. ( not only a part from it ).
     
    farad, Dec 12, 2008 IP
  3. LinksMaster

    LinksMaster Peon

    Messages:
    129
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3

    my message is $message = '<p>Your Detail</p><p> text here </p>';
     
    LinksMaster, Dec 12, 2008 IP
  4. drunnells

    drunnells Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Maybe the problem is not with your code. Check your mail server logs to see if the message was received for delivery, but perhaps failed for some other reason (DNS, queue issues, etc). Is this a linux/unix server? From your form try sending a message to a local user, maybe "root" or something. If that works the problem may be that you don't have your mail server configured correctly or maybe you have a firewall that is preventing this kind of outbound traffic?
     
    drunnells, Dec 12, 2008 IP
  5. LinksMaster

    LinksMaster Peon

    Messages:
    129
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for your comment

    Yes my server is linux. But not send mail.
     
    LinksMaster, Dec 12, 2008 IP
  6. LinksMaster

    LinksMaster Peon

    Messages:
    129
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Please help me !

    any one can help me
     
    LinksMaster, Dec 12, 2008 IP
  7. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think problem is wt your hosting provider disabled mail function...
     
    ignas2526, Dec 12, 2008 IP
  8. drunnells

    drunnells Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Do you have shell access to this linux server via telnet or ssh or anything? If so, try this. I will assume your shell login is "LinksMaster". From the command line do:

    echo 'test' |mail LinksMaster --subject='test message'
    Code (markup):
    And then run "mail" from the command line with no options to see if you received the test message. If that works, have your form send mail to "LinksMaster" too and check with the mail command again to see if you received it. If so, your mail server just can't send mail out and you need to find out why.

    Also, were you able to check your mail logs yet? That will be a key indicator of where the problem is.

    If your hosting provider prevents your mail server from sending mail out, you may be able to use a custom function to send the mail to an external mail server (if you have one) and out from there.. i've used this code for such things before (i don't remember where i found it, but it works great!):

    function SendMail($ToName, $ToEmail, $FromName, $FromEmail, $Subject, $Body, $Header) {
            $SMTP = fsockopen("mail.externalmailserver.com", 25);
            $InputBuffer = fgets($SMTP, 1024);
            fputs($SMTP, "HELO userbars.com\n");
            $InputBuffer = fgets($SMTP, 1024);
            fputs($SMTP, "MAIL From: $FromEmail\n");
            $InputBuffer = fgets($SMTP, 1024);
            fputs($SMTP, "RCPT To: $ToEmail\n");
            $InputBuffer = fgets($SMTP, 1024);
            fputs($SMTP, "DATA\n");
            $InputBuffer = fgets($SMTP, 1024);
            fputs($SMTP, "$Header");
            fputs($SMTP, "From: $FromName <$FromEmail>\n");
            fputs($SMTP, "To: $ToName <$ToEmail>\n");
            fputs($SMTP, "Subject: $Subject\n\n");
            fputs($SMTP, "$Body\r\n.\r\n");
            fputs($SMTP, "QUIT\n");
            $InputBuffer = fgets($SMTP, 1024);
            fclose($SMTP);
    } 
    Code (markup):
     
    drunnells, Dec 12, 2008 IP
  9. LinksMaster

    LinksMaster Peon

    Messages:
    129
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks!

    you help me.

    But i have not shell excess .

    In this code i have not get any type of error ..

    How i find what is the problem behind the server



    Regards,
    Ronny
     
    LinksMaster, Dec 12, 2008 IP
  10. develope_with_me

    develope_with_me Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Check your mail server logs to see the problem...
     
    develope_with_me, Dec 15, 2008 IP