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.
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.