Problem sending mail using PHP's mail() function.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vivekshekar
    New Member
    • Jul 2008
    • 11

    Problem sending mail using PHP's mail() function.

    I'm using Ubuntu OS,

    I'm trying to send a mail through a program, but I'm not able to do this.

    This is the program,

    Code:
    <?php
    
    $Name = "xxx"; 
    $email = "xxx@xxx.com"; 
    $recipient = "xxx@xxx.com"; 
    $mail_body = "The text for the mail..."; 
    $subject = "Testing mail"; 
    $header = "From: ". $Name . " <" . $email . ">\r\n"; 
    
    if
    (mail($recipient, $subject, $mail_body, $header))
    	{
    	  echo("Message sent");
    	}
    	else{
             echo("Not sent");
           }
    ?>
    Plz... help me to come out of this prob.
    Last edited by Atli; Sep 13 '08, 05:23 AM. Reason: Made the title a little clearer
  • theS70RM
    New Member
    • Jul 2007
    • 107

    #2
    how about some more info..

    like what if any error messages you get?

    throw us a bone here!

    Comment

    • vivekshekar
      New Member
      • Jul 2008
      • 11

      #3
      It will just display on browser that "Not sent".

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Try to turn on the error messages and see what that tells you.

        There is essentially nothing wrong with that code. The problem is with your OS. For the mail() function to work, PHP must be configured correctly, the [mail] section has to be set to valid values.

        I recommend avoiding the mail function. There are better methods available, such as the PHPMailer class, or the Swift Mailer class.

        I would recommend trying them first.

        Comment

        • vivekshekar
          New Member
          • Jul 2008
          • 11

          #5
          I have turned on the error messages, but it is not showing any error, and even not sending the mail.
          Even now it's displaying "not sent".

          Yes! I will try PHPMailer, and swiftmailer.

          But I want this "mail()" should work.


          Thanx...


          Originally posted by Atli
          Hi.

          Try to turn on the error messages and see what that tells you.

          There is essentially nothing wrong with that code. The problem is with your OS. For the mail() function to work, PHP must be configured correctly, the [mail] section has to be set to valid values.

          I recommend avoiding the mail function. There are better methods available, such as the PHPMailer class, or the Swift Mailer class.

          I would recommend trying them first.

          Comment

          Working...