php mail() not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wasco
    New Member
    • Feb 2010
    • 3

    php mail() not working

    Hi i am writing a php code to send email from my exchange server to user. however, keep receiving the the Warning message below:
    Warning: Unknown error in c:\phpdev5\www\ mailtest2.php on line 5

    my php code:

    [CODE=php]<?php
    $to = "test1@example. com";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";
    if (mail($to, $subject, $body)) {
    echo("<p>Messag e successfully sent!</p>");
    } else {
    echo("<p>Messag e delivery failed...</p>");
    }
    ?>[/CODE]

    php.ini setting:
    Code:
    [mail function]
    ; For Win32 only.
    
    SMTP = gss-exchange1.example.com
    SMTP_Port = 25
    
    ; For Win32 only.
    
    sendmail_from = test2@example.com
    Can anyone pls tel me what's wrong with my code or php setting?

    Thanks.
    Last edited by Atli; Feb 5 '10, 11:03 AM. Reason: Added [code] tags and replaced real email addresses with examples.
  • hitendrap
    New Member
    • Sep 2009
    • 9

    #2
    wasco, you need to set up a real mailing server in order to send a real mail,
    read more about mail() function on php.net ,
    if you are on windows, try to use free smtp server http://www.softstack.com/freesmtp.html

    if you are lucky mail will be sent !!!

    also read abt setting up Gmail as SMTP server

    Comment

    • wasco
      New Member
      • Feb 2010
      • 3

      #3
      Originally posted by hitendrap
      wasco, you need to set up a real mailing server in order to send a real mail,
      read more about mail() function on php.net ,
      if you are on windows, try to use free smtp server http://www.softstack.com/freesmtp.html

      if you are lucky mail will be sent !!!

      also read abt setting up Gmail as SMTP server
      Hi Hitendrap,

      Thanks for your reply.

      I have downloaded and installed the free smtp server; no luck for me, keeping getting "Waiting for connections on Port#25; using DNS Server: 170.133.125.2 (my company dns)

      Comment

      • hitendrap
        New Member
        • Sep 2009
        • 9

        #4
        Remember that DNS server is not a mailing server (you need to get the IP of mail server from ur network admin, the DNS server contains the MX record for the mail server)

        Make sure you also ask for the port number once you get thr mail serevr IP and set the configuration in PHP.INI

        while your mailing program is being executed, just watch the freesmtpserver window, it shows the recipients e-mail address with hourglass icon before that !

        Comment

        • wasco
          New Member
          • Feb 2010
          • 3

          #5
          Hi Hitendrap,

          I have added SMTP address(Given by Network admin) to the php.ini and received the following message when i execute my php program:

          Warning: Unknown error in c:\phpdev5\www\ mailtest3.php on line 7

          my php code:

          Code:
          $to = "test1@gss.com";
          $subject = "Test mail";
          $message = "Hello! This is a simple email message.";
          $from = "test2@gss.com";
          $headers = "From: $from";
          [B]mail[/B]($to,$subject,$message,$headers);
          echo "Mail Sent.";
          ?>
          Do i need to include the test2 (sender) user id and password in my php code in order to connect to my smtp mail server (exchange mail server)?

          Thanks in advance!
          Last edited by Dormilich; Feb 9 '10, 06:39 AM. Reason: Please use [code] tags when posting code

          Comment

          • hitendrap
            New Member
            • Sep 2009
            • 9

            #6
            Not necessary as far as the SMTP server allows without authentication.

            and headers are optional in mail() function.

            avoid writing words like test, example in mails even the addresses,
            coz' some popular Mailing servers like Gmail, Yahoo may put your test mail in Spam OR even block the mail.

            Comment

            Working...