473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Simple mail problem

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
5 3075

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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alexander Ross | last post by:
I am trying to create a simple mail form (i.e. five fields, the users pushes send and using the mail function I get an email with their input values). The problem is that some people will be...
0
by: Hal Vaughan | last post by:
I'm working with javax.mail.*. I have no problem with reading in messages. I'm not using multi-part messages or anything, I just use this setup: Session oSession =...
6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
6
by: Benny Alexander | last post by:
Hi, I am using a simple form 2 email program. I ama experienced programmer, But I feel very bad, as I am unable to fix this problem. All seems to be fine, But the mail is not reacing to my...
9
by: savvy | last post by:
i'm trying to compile a simple console application for sending a mail, my main idea is to schedule it to a particular time for sending mails using the windows schedular task lateron. Therefore i...
5
by: Logickle | last post by:
Hi, all. I'm working on an application which requires communicating session info between separate web apps running on the same web server. The out of process server method sounded ideal, and...
5
by: Olivier/Noetika | last post by:
would like to send messages from my vb application with the user default mail software. That's to say preparing content, attachement and let user selecting the "to" option with it's own friends list....
4
by: Tony M | last post by:
VS 2005 - XP media - VB .net - winforms - .net 2.0 Just trying to send an email, here is the code and the error message that I get. I can't figure out how to fix it?
5
by: simononestop | last post by:
Hi im totally new to perl this is my first go at using it (I normally use asp). I have set up a form with a cgi script from demon hosting. I have edited the script and the form works it sends me an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.