By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,503 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

Simple mail problem

P: n/a
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>
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

Bruce W...1 <br***@noDirectEmail.com> wrote in message
news:3F***************@noDirectEmail.com...
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>

It looks like the dreaded register globals problem.

Try adding these four lines of code:

$vars = array_merge($HTTP_POST_VARS, $HTTP_GET_VARS);

$email = $vars['email'];
$message = $vars['message'];
$subject = $vars['subject'];


Jul 17 '05 #2

P: n/a
Jeff Darling wrote:


It looks like the dreaded register globals problem.

Try adding these four lines of code:

$vars = array_merge($HTTP_POST_VARS, $HTTP_GET_VARS);

$email = $vars['email'];
$message = $vars['message'];
$subject = $vars['subject'];

================================================== ======

Not sure what you mean.

Well I stripped it down to bare bones and it successfully sent an email. See
code below. But I don't understand why the code in my original post doesn't
work. I have much to learn.

Code follows:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Send mail
<?php
$to2 = "nb@whatever.com";
$subject2 = "New whatever";
$body2 = "A new whatever was submitted";
$from2 = "From: au*********@whatever.com";
mail($to2, $subject2, $body2, $from2);
?>
</body>
</html>
Jul 17 '05 #3

P: n/a
Jeff Darling wrote:

It looks like the dreaded register globals problem.

Try adding these four lines of code:

$vars = array_merge($HTTP_POST_VARS, $HTTP_GET_VARS);

$email = $vars['email'];
$message = $vars['message'];
$subject = $vars['subject'];


================================================== ====

I think you're on to something. I set register_globals to On in php.ini and it
works properly. But I don't really understand this.
Jul 17 '05 #4

P: n/a

"Bruce W...1" <br***@noDirectEmail.com> wrote in message
news:3F***************@noDirectEmail.com...
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.


One of the bugs reported for 4.3.3 is the mail() function not working.

I upgraded from 4.3.2 to 4.3.3, resulting in no more working mail()
function, I upgraded again to 4.3.4dev and mail() is now working again.

system: Windows XP pro running IIS5 and PHP CGI exe / Apache 2.47 and PHP
apache 2 module with the same php.ini for both.

Jul 17 '05 #5

P: n/a
Richard Hockey wrote:

One of the bugs reported for 4.3.3 is the mail() function not working.

I upgraded from 4.3.2 to 4.3.3, resulting in no more working mail()
function, I upgraded again to 4.3.4dev and mail() is now working again.

system: Windows XP pro running IIS5 and PHP CGI exe / Apache 2.47 and PHP
apache 2 module with the same php.ini for both.

================================================== ==========

Good to know. I'm running Windows 2000 and PHP build 4.3.3 with IIS. Mail()
does indeed work. The problem seems to be that I'm using a script meant for
register_globals to be On. It's Off in 4.3.3 and I'd just as soon leave it that
way.

PHP is not strong when it comes to tracing and error messages so I'm shooting in
the dark.

I rewrote it to avoid the register_globals problem, I think. See the code
below. And I put some echo messages in the code to find where the problem is
but they aren't working either. On the first postback it does nothing, it
doesn't hit any of my echo lines and it's driving me crazy without giving me any
error messages or anything. It's like it's not executing any code at all on
postback. It should do either the if or the else.

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($_POST['email']) or !isset($_POST['message'])) {
//if (!isset($email) or !isset($message)) {
show_form();
echo "Showing form";
}
else {
echo "First else hit";

$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$subject = $_REQUEST['subject'];

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.";
}
if (empty($message)) {
echo "You did not write anything. Please write something.";
}
show_form($email,$message,$subject);
}
else {
echo "Second else hit";
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>
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.