Hi,

I have been trying to do something that looks simple: to put one button called "Notify" that sends the same message every time it is clicked on. After it sends the message, it goes to menuwebmaster.php. I think I am not doing this the right way. Anyone can help?

<input type="button" name="mail" value="Notify" class="bodb" onClick="location.href=\'menuwebmaster.php\';">

$mailTo ="x@x.org";
$mailFrom ="y@y.org";
$mailSubject="Hi from me";
$mailBody ="This is a notification";

mail($mailTo, $mailSubject, $mailBody, "Content-Type:text/plain\nFrom: $mailFrom");

    Try this...

    <?php
    //Put this at the very top of the page
    if(isset($_GET['send'])){
        $mailTo ="x@x.org";
        $mailFrom ="y@y.org";
        $mailSubject="Hi from me";
        $mailBody ="This is a notification";
        $headers = "Content-Type: text/plain\r\n";
        $headers .= "From: $mailFrom\r\nReply-to: $mailFrom\r\nReturn-path: $mailFrom\r\n";
    
    
    if(mail($mailTo, $mailSubject, $mailBody, "Content-Type:text/plain\nFrom: $mailFrom")){
        header('Location: menuwebmaster.php');
    }else{
        echo 'Error in sending mail.';
    }
    }
    ?>
    <input type="button" name="mail" value="Notify" class="bodb" onclick="window.location = '?send'" />
    

      Hi Stryker250!

      Thanks so much for your quick reply.

      I have tried what you told me, but it gives me an error. The problem may be that I want this button between some other buttons. I cannot put the Notify button at the very top.

      This is where I want to put the "Notify" button:

      print('<tr><td colspan="2" align="center"><input type="submit" name="Enviar" value="Enviar" class="bodb">
      <input type="reset" name="Limpiar" value="Limpiar" class="bodb">
      <input type="button" name="Volver" value="Volver" class="bodb" onClick="location.href=\'MenuArticulos.php?0&'.$letrabuscada.'\';">RIGHT HERE</td></tr></table></form>');

      It is a long page of code, and this is at the end. By the way, if there are words you don't understand, that is Spanish :o)

      Thanx again for your help. Much appreciated!
      Andy

        You don't need to keep the button and the PHP script together. You only need the PHP script near the top of the page, before any HTML output. Otherwise you will receive an error from PHP saying that headers have already been sent.

          HI,

          It gives me errors. This is the beginning of my page:

          <?
          header("Cache-Control:no-cache,must-revalidate");
          if($admin!="S"){print("<script language='JavaScript'>location.href='../index.php';</script>");}
          ?>
          <? php
          if(isset($_GET['send'])){
          $mailTo ="x@x.org";
          $mailFrom ="y@y.org";
          $mailSubject="hi from me";
          $mailBody ="This is a notification";
          $headers = "Content-Type: text/plain\r\n";
          $headers .= "From: $mailFrom\r\nReply-to: $mailFrom\r\nReturn-path: $mailFrom\r\n";

          if(mail($mailTo, $mailSubject, $mailBody, "Content-Type:text/plain\nFrom: $mailFrom")){
              header('Location: menuwebmaster.php');
          }else{
              echo 'Error in sending mail.'; [COLOR="Red"][B]THIS LINE GIVES AN ERROR[/B][/COLOR]
          }

          }
          ?>

          <html>
          <head>
          <title>Área privada</title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          <link rel="stylesheet" href="../estilos/h2.css">
          <script language='JavaScript'> IF I DELETE THE ELSE (previous error), THEN THIS LINE GIVES AN ERROR
          <!--
          var caracteristicas='channelmode=0,dependent=0,directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,screenX=0,screenY=0,width=800,height=450';
          //-->
          </script>
          </head>

          Any clue what is going on?
          Thanks again!

            Mind posting what the error is? I'm not exactly sure what could have caused an error on those lines.

              Some of the code looks a little mish-mashed.

              <?
              header("Cache-Control:no-cache,must-revalidate");
              if($admin!="S"){print("<script language='JavaScript'>location.href='../index.php';</script>");}
              ?>
              <? php
              

              There should be no space between <? and php, and you should really use <?php instead of just <?. Also, you're closing a PHP segment and then opening up another immediately, you ought to get rid of the last two lines in the excerpt I took.

                The error I get is: "Parse error: parse error, unexpected T_IF in ..... line ...."

                  Have you removed those two lines I mentioned? Upon removal, are you still getting the errors?

                    Hi Ashley Sheridan

                    Not sure what two lines you refer to. This is what I have at the top of the page right now:

                    <?
                    header("Cache-Control:no-cache,must-revalidate");
                    if($admin!="S"){print("<script language='JavaScript'>location.href='../index.php';</script>");}
                    ?>
                    <? php
                    if(isset($_GET['send'])){
                    $mailTo ="x@x.org";
                    $mailFrom ="y@y.org";
                    $mailSubject="Hi from me";
                    $mailBody ="This is a notification";
                    $headers = "Content-Type: text/plain\r\n";
                    $headers .= "From: $mailFrom\r\nReply-to: $mailFrom\r\nReturn-path: $mailFrom\r\n";

                    if(mail($mailTo, $mailSubject, $mailBody, "Content-Type:text/plain\nFrom: $mailFrom")){
                        header('Location:menuwebmaster.php');
                    }else{
                        echo 'Error in sending mail.';
                    }

                    }
                    ?>

                      remove lines 4 and 5:

                      ?>
                      <? php
                      

                      As it is pointless closing and opening a PHP script like this, and I think the extra space before the "php" is creating the error.

                        Done it. I removed the line and changed the first line. Got rid of initial problems. Now I have this error in line 88 where the button is: "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING"

                        This is code where the button is:

                        print('<form method="post" action="ActualizarArticulos.php?'.$regact.'">
                        <input type="hidden" name="regedita" value="'.$regvir.'">
                        <input type="hidden" name="tabla" value="articulos">
                        <table align="center">
                        ');
                        include("DatosEdForms.php");
                        $letrabuscada=substr($ValEditCampo[2],0,1);
                        print('<tr><td colspan="2" align="center"><input type="submit" name="Enviar" value="Enviar" class="bodb">
                        <input type="reset" name="Limpiar" value="Limpiar" class="bodb">
                        <input type="button" name="Volver" value="Volver" class="bodb" onClick="location.href=\'MenuArticulos.php?0&'.$letrabuscada.'\';"></td></tr></table>
                        <input type="button" name="mail" value="Notify" class="bodb" onclick="window.location = '?send'" /></form>');
                        ERROR IS IN THIS LINE

                          The error there is clear. You are using single quotes for the JavaScript, but you are also using single quotes for the PHP string. You should escape them out with backslashes, like: "window.location = \'?send\'"

                            Thanx a million!!! It works perfectly well !!!!

                              Write a Reply...