Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2003
    Location
    USA
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Warning: mail(): "sendmail_from" not set in php.ini

    I'm attempting to send an e-mail via a form. In the book I'm using, I'm on the chapter of creating, writing, and reading files. It's also got something on sending e-mails, with the content of the e-mail being a previously written file. I'm attempting to have a form, where the user inputs a e-mail address, and the message, and the script will open a file, write the message to a file, then open the file again, and send it as an e-mail. It's basically like the book shows, except I'm having the user input the message and such before hand.

    You can see the form page here.
    Not sure if there's anything else wrong, but I get an error when submitting the form:

    Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in c:\program files\apache group\apache\htdocs\files\sendmail.php on line 17


    Contents of form page:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    >

    <
    html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <
    head><title>PHP Test Page</title>
    <
    meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" /> 
    <
    meta http-equiv="Content-Style-Type" content="text/css" />
    <
    meta http-equiv="Content-Script-Type" content="text/javascript" />
    </
    head>

    <
    body onload="document.forms[0].reset();">

    <
    form method="post" action="sendmail.php" name="E-mail Form">
    <
    input type="text" name="addy" size="47" value="Reciever's E-mail Address" onfocus="if(this.value==value){this.value='';}" /> <br />
    <
    textarea name="contents" cols="35" rows="10"></textarea> <br />
    <
    input type="submit" name="submit" value="Send Mail" />
    </
    form>

    </
    body>
    </
    html
    And the "sendmail.php" page:
    PHP Code:
    <?php
    if(($_POST['addy'] == "") && ($_POST['contents'] == "")) {
    header ("Location: /files/e-mail.php"); 
    exit;
    }

    else {
    $my_file "C:\Documents and Settings\Paul James\My Documents\\my_file.txt";
    $file_msg $_POST['contents'];
    $open_file = @fopen($my_file"w+") or die ("<strong>Error: </strong> Could Not Open ".$my_file);
    @
    fwrite ($open_file$file_msg) or die ("<strong>Error: </strong> Unable To Write To File ".$my_file);
    $msg "Data Has Been Written.";
    $open_file2 fread($open_filefilesize($my_file));
    $to $_POST['addy'];
    $subject "File Contents";
    $mailheaders "From: My Website <> \n";
    mail($to$subject$open_file2$mailheaders);
    $msg .= " Check Your Mail!";
    fclose($open_file);

    }
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head><title>PHP Test Page</title>
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" /> 
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    </head>

    <body>

    <?php
    echo $msg;
    ?>

    </body>
    </html>
    Now, is what I'm trying to do possible? I'm not sure if it is, but I figured I'd give it a try.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 96 Times in 94 Posts
    On win32 , if your ISP's mailserver (rightly) requires authentication the mail() function won't actually work , unless you have a local mailserver.


    In saying that, from your error message it looks like the script is trying ... so try altering the header...

    $mailheaders = "From: me@mydomain.com\r\n";

    the manual notes that under windows "blah<blah@blah.com>" may not work as expected .
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Dec 2003
    Location
    USA
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First of all, lemme point out (since I believe it's important), that I'm running this off my 'puter. I've got PHP 4.3.4 installed, with Apache 1.3.28 for Windows.

    Now, if I understand you correctly...
    This:
    PHP Code:
    $mailheaders "From: My Website <> \n"
    Should be:
    PHP Code:
    $mailheaders "From: <myemail@hotmail.com> \r\n"
    Yes? No?
    Your help is much appreciated by my newbie self.

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 96 Times in 94 Posts
    Hi , yes but try both ..

    $mailheaders = "From: <myemail@hotmail.com>\r\n";

    if no joy try

    $mailheaders = "From: myemail@hotmail.com\r\n";


    else its probably one of the other problems noted above.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •