In my effort to learn PHP I'm playing with some simple email scripts. They
worked a few days ago but they stopped working. The only thing I've done to
this Windows 2000 PC in this time was a Windows Update which I do regularly.
The only part of this update that might be related was an IE 6 update.
So I uninstalled and reinstaled PHP 4.3.3. The mail server setting is correct
in the php.ini file. But email is still not being sent.
PHP seems to be working because I put an echo statement in the code that works.
Notice in the code below that if you don't put anything in the textboxes it's
supposed to give a friendly error message. It does not.
Can anyone give me tips on how to track down the source of why the mail send and
error messages don't work?
Thanks for your help.
The code follows:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php function show_form($email="", $message="", $subject="") { ?>
<h2>Send Me an E-mail</h2>
<form action="mail.php" method="post">
Your E-mail address:<br>
<input type=text name=email size=30
value="<?php echo $email?>"><br>
The Subject:<br>
<input type=text name=subject size=30
value="<?php echo $subject?>"><br>
Your Message:<br>
<textarea rows=10 cols=50 name=message><?php echo $message?></textarea><br>
<input type=submit value="Send E-mail">
</form>
<?php }
if (!isset($email) or !isset($message)) {
show_form();
}
else {
if (empty($email) or empty($message)) {
echo "<H1>There is a Problem:</H1>";
if (empty($email)) {
echo "I need your email address in order to write back.
Please fill it in below. Thank you.";
}
if (empty($message)) {
echo "You did not write anything. Please write something.
Thank You.";
}
show_form($email,$message,$subject);
}
else {
if (empty($subject)) {
$subject="your email";
}
$sent = mail( "nb@whatever.com", $subject, $message, "From: $email" );
if ($sent) {
echo "<H1>Your Message Has Been Sent.</H1>";
echo "Thank you, <b>$email</b>. <p>I'll will read your email regarding
'
<b>$subject</b> and reply soon.";
}
else {
echo "<H1>There is a Problem:</H1>
<p>The server was unable to send your mail.";
}
}
}
?>
</body>
</html>