Simple mail problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce W...1

    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>Untitl ed Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>

    <?php function show_form($emai l="", $message="", $subject="") { ?>

    <h2>Send Me an E-mail</h2>

    <form action="mail.ph p" 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($emai l,$message,$sub ject);
    }
    else {
    if (empty($subject )) {
    $subject="your email";
    }

    $sent = mail( "nb@whatever.co m", $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>
  • Jeff Darling

    #2
    Re: Simple mail problem


    Bruce W...1 <bruce@noDirect Email.com> wrote in message
    news:3F84A226.C E36AEFD@noDirec tEmail.com...[color=blue]
    > In my effort to learn PHP I'm playing with some simple email scripts.[/color]
    They[color=blue]
    > worked a few days ago but they stopped working. The only thing I've done[/color]
    to[color=blue]
    > this Windows 2000 PC in this time was a Windows Update which I do[/color]
    regularly.[color=blue]
    > 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[/color]
    correct[color=blue]
    > 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[/color]
    works.[color=blue]
    >
    > Notice in the code below that if you don't put anything in the textboxes[/color]
    it's[color=blue]
    > 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[/color]
    send and[color=blue]
    > error messages don't work?
    >
    > Thanks for your help.
    >
    > The code follows:
    >
    > <html>
    > <head>
    > <title>Untitl ed Document</title>
    > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    > </head>
    > <body>
    >
    > <?php function show_form($emai l="", $message="", $subject="") { ?>
    >
    > <h2>Send Me an E-mail</h2>
    >
    > <form action="mail.ph p" 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[/color]
    $message?></textarea><br>[color=blue]
    >
    > <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($emai l,$message,$sub ject);
    > }
    > else {
    > if (empty($subject )) {
    > $subject="your email";
    > }
    >
    > $sent = mail( "nb@whatever.co m", $subject, $message, "From:[/color]
    $email" );[color=blue]
    >
    > if ($sent) {
    > echo "<H1>Your Message Has Been Sent.</H1>";
    > echo "Thank you, <b>$email</b>. <p>I'll will read your email[/color]
    regarding[color=blue]
    > '
    > <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>[/color]


    It looks like the dreaded register globals problem.

    Try adding these four lines of code:

    $vars = array_merge($HT TP_POST_VARS, $HTTP_GET_VARS) ;

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




    Comment

    • Bruce W...1

      #3
      Re: Simple mail problem

      Jeff Darling wrote:[color=blue]
      >
      >
      > It looks like the dreaded register globals problem.
      >
      > Try adding these four lines of code:
      >
      > $vars = array_merge($HT TP_POST_VARS, $HTTP_GET_VARS) ;
      >
      > $email = $vars['email'];
      > $message = $vars['message'];
      > $subject = $vars['subject'];[/color]
      =============== =============== =============== ===========

      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>Untitl ed Document</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>
      <body>
      Send mail
      <?php
      $to2 = "nb@whatever.co m";
      $subject2 = "New whatever";
      $body2 = "A new whatever was submitted";
      $from2 = "From: autoconfirm@wha tever.com";
      mail($to2, $subject2, $body2, $from2);
      ?>
      </body>
      </html>

      Comment

      • Bruce W...1

        #4
        Re: Simple mail problem

        Jeff Darling wrote:[color=blue]
        >
        > It looks like the dreaded register globals problem.
        >
        > Try adding these four lines of code:
        >
        > $vars = array_merge($HT TP_POST_VARS, $HTTP_GET_VARS) ;
        >
        > $email = $vars['email'];
        > $message = $vars['message'];
        > $subject = $vars['subject'];[/color]

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

        I think you're on to something. I set register_global s to On in php.ini and it
        works properly. But I don't really understand this.

        Comment

        • Richard Hockey

          #5
          Re: Simple mail problem


          "Bruce W...1" <bruce@noDirect Email.com> wrote in message
          news:3F84A226.C E36AEFD@noDirec tEmail.com...[color=blue]
          > In my effort to learn PHP I'm playing with some simple email scripts.[/color]
          They[color=blue]
          > worked a few days ago but they stopped working. The only thing I've done[/color]
          to[color=blue]
          > this Windows 2000 PC in this time was a Windows Update which I do[/color]
          regularly.[color=blue]
          > 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[/color]
          correct[color=blue]
          > in the php.ini file. But email is still not being sent.[/color]

          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.



          Comment

          • Bruce W...1

            #6
            Re: Simple mail problem

            Richard Hockey wrote:[color=blue]
            >
            > 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.[/color]
            =============== =============== =============== ===============

            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_global s 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_global s 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>Untitl ed Document</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            </head>

            <body>

            <?php function show_form($emai l="", $message="", $subject="") { ?>

            <h2>Send Me an E-mail</h2>

            <form action="mail.ph p" 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($emai l,$message,$sub ject);
            }
            else {
            echo "Second else hit";
            if (empty($subject )) {
            $subject="your email";
            }

            $sent = mail( "nb@whatever.co m", $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>

            Comment

            Working...