send email automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • taurus89
    New Member
    • Feb 2010
    • 6

    send email automatically

    helo......
    i want to send email automatically.. but it doesn't work...
    and display msg not sent..
    this is my code....plz check if there any error.......
    i'm a new in php... plz help me...

    Code:
    $recipent = "smile@example.com";
    $subject = "attention";
    
    $fname = "farah";
    $email = "wfarah@example.com";
    $msg = "fail";
    
    $body = "Sender: " . $fname . "\n\nEmail: " . $email . "\n\nMessage:\n\n" . $msg;
    if (@mail($recipent, $subject, $body)) { echo "msg sent"; }
    else { echo "msg not sent"; }
    Last edited by Atli; Apr 1 '10, 06:27 AM. Reason: Added [code] tags and replaced real email addresses with example values.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    There is nothing essentially wrong with the code. No syntax errors or such. If the mail() function is configured correctly, this should work.

    Try to turn on the debug messages and remove the @ in from of the mail() function. - That might generate some error messages to help debug this.

    Comment

    • taurus89
      New Member
      • Feb 2010
      • 6

      #3
      it will display error message like this...
      Warning: mail() [function.mail]: "sendmail_f rom" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs \proj_prktkl\li st_extract.php on line 19
      msg not sent

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        You are missing the the "From" address.

        It can be set like the error message describes, in the php.ini configuration file, or you can do it manually by adding a custom From header. (See example #2 in the manual entry for the mail function.)

        Comment

        Working...