...

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



Paul Jr
01-19-2004, 12:57 AM
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 (http://www.mysteriously.no-ip.com/files/e-mail.php).
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:


<!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
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_file, filesize($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.

firepages
01-19-2004, 02:52 AM
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 .

Paul Jr
01-19-2004, 06:34 AM
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:


$mailheaders = "From: My Website <> \n";

Should be:


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

Yes? No?
Your help is much appreciated by my newbie self. ;)

firepages
01-19-2004, 03:31 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum