PHP email form not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alice

    #1

    PHP email form not working

    I found this code for making a php email form for a web site. It works
    fine on my ISP, but not on my friends...could it be that my ISP uses
    php5, I know that hers does not, so I assume it's php4. Is there anyway
    to tell? Here's the code. It sends me email fine, but when it's on her
    ISP, it says it sent the mail, but nothing goes through.

    <?php
    if (isset($submit) ) {
    switch ($recipient) {
    case "whole-family":
    $recipient_emai l = "gregf@kcls.org ";
    $subject = "Gregs test php mail";
    break;
    case "Brian":
    $recipient_emai l = "brian@meye r-family.com";
    $subject = "Message to Brian";
    break;
    case "Jessica":
    $recipient_emai l = "jessica@me yer-family.com";
    $subject = "Message to Jessica";
    break;
    case "Eric":
    $recipient_emai l = "eric@meyer-family.com";
    $subject = "Message to Eric";
    break;
    case "Paul":
    $recipient_emai l = "paul@meyer-family.com";
    $subject = "Message to Paul";
    break;
    case "Dudley":
    $recipient_emai l = "dudley@mey er-family.com";
    $subject = "Message to Dudley";
    break;
    }

    if (!empty($name) and !empty($email) and !empty($message )) {
    if (mail ($recipient_ema il, $subject, $message, "From: $name
    <$email>"))
    $status = "<p>Thanks for your message, $name, it has been
    successfully
    sent!</p>";
    else
    $status = '<p>Your message couldnt be sent! Please try again or
    send
    us a conventional e-mail to
    <a href="mailto:gr egf@kcls.org">g regf@kcls.org</a>.
    Thank you!</p>';
    }
    else
    $status = "Please fill the highlighted fields!";
    }
    ?>

    <html>
    <head>
    <title>www.meyer-family.com - Contact</title>
    <style type="text/css">
    <!--
    .error { font-weight: bold; color: red; }
    -->
    </style>
    </head>
    <body>
    <h1>Contact</h1>
    <?php
    if(isset($statu s))
    echo ($status);
    ?>
    <form action="contact .php" method="post">
    <p>Send message to:
    <select name="recipient " size="1">
    <option value="whole-family">The whole Meyer family</option>
    <option value="Brian">B rian</option>
    <option value="Jessica" >Jessica</option>
    <option value="Eric">Er ic</option>
    <option value="Paul">Pa ul</option>
    <option value="Dudley"> Dudley</option>
    </select></p>
    <p<?php
    if (isset($submit) and empty($name))
    echo(' class="error"') ;
    ?>>Your name:
    <input type="text" name="name" value="<?php if(!empty($name ))
    echo($name); ?>" size="30"
    /></p>
    <p<?php
    if (isset($submit) and empty($email))
    echo(' class="error"') ;
    ?>>Your e-mail address:
    <input type="text" name="email" value="<?php if(!empty($emai l))
    echo($email); ?>"
    size="30" /></p>
    <p<?php
    if (isset($submit) and empty($message) )
    echo(' class="error"') ;
    ?>>Your message:
    <textarea name="message" cols="30" rows="5"><?php
    if(!empty($mess age))
    echo($message);
    ?></textarea></p>
    <input type="submit" name="submit" value="Send" />
    </form>
    </body>
    </html>

  • Rik

    #2
    Re: PHP email form not working

    alice wrote:
    I found this code for making a php email form for a web site. It works
    fine on my ISP, but not on my friends...could it be that my ISP uses
    php5, I know that hers does not, so I assume it's php4. Is there
    anyway to tell? Here's the code. It sends me email fine, but when
    it's on her ISP, it says it sent the mail, but nothing goes through.
    Look for register_global s and the $_POST array.
    --
    Rik Wasmus


    Comment

    • Michael Austin

      #3
      Re: PHP email form not working

      Rik wrote:
      alice wrote:
      >
      >>I found this code for making a php email form for a web site. It works
      >>fine on my ISP, but not on my friends...could it be that my ISP uses
      >>php5, I know that hers does not, so I assume it's php4. Is there
      >>anyway to tell? Here's the code. It sends me email fine, but when
      >>it's on her ISP, it says it sent the mail, but nothing goes through.
      >
      >
      Look for register_global s and the $_POST array.
      Here is a piece of code I found a long time ago that would extract all of the
      get/post'ed variables if register_global s is off. Place this at the top of your
      code...

      if (!empty($_GET))
      {
      extract($_GET);
      }
      else if (!empty($HTTP_G ET_VARS))
      {
      extract($HTTP_G ET_VARS);
      }

      if (!empty($_POST) )
      {
      extract($_POST) ;
      }
      else if (!empty($HTTP_P OST_VARS))
      {
      extract($HTTP_P OST_VARS);
      }

      --
      Michael Austin.
      Database Consultant

      Comment

      • alice

        #4
        Re: PHP email form not working

        Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
        where this code does not work, is using php 4.4. Should I still try the
        code your talking about, would it make any difference? We also
        discovered that other php mail/form code that she had on her ISP that
        was working the day before, has suddenly stopped working, but we
        haven't changed anything ourselves.

        Michael Austin wrote:
        Rik wrote:
        >
        alice wrote:
        >I found this code for making a php email form for a web site. It works
        >fine on my ISP, but not on my friends...could it be that my ISP uses
        >php5, I know that hers does not, so I assume it's php4. Is there
        >anyway to tell? Here's the code. It sends me email fine, but when
        >it's on her ISP, it says it sent the mail, but nothing goes through.

        Look for register_global s and the $_POST array.
        >
        Here is a piece of code I found a long time ago that would extract all of the
        get/post'ed variables if register_global s is off. Place this at the top of your
        code...
        >
        if (!empty($_GET))
        {
        extract($_GET);
        }
        else if (!empty($HTTP_G ET_VARS))
        {
        extract($HTTP_G ET_VARS);
        }
        >
        if (!empty($_POST) )
        {
        extract($_POST) ;
        }
        else if (!empty($HTTP_P OST_VARS))
        {
        extract($HTTP_P OST_VARS);
        }
        >
        --
        Michael Austin.
        Database Consultant

        Comment

        • Michael Austin

          #5
          Re: PHP email form not working

          alice wrote:
          Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
          where this code does not work, is using php 4.4. Should I still try the
          code your talking about, would it make any difference? We also
          discovered that other php mail/form code that she had on her ISP that
          was working the day before, has suddenly stopped working, but we
          haven't changed anything ourselves.
          >
          Michael Austin wrote:
          >
          >>Rik wrote:
          >>
          >>
          >>>alice wrote:
          >>>
          >>>
          >>>>I found this code for making a php email form for a web site. It works
          >>>>fine on my ISP, but not on my friends...could it be that my ISP uses
          >>>>php5, I know that hers does not, so I assume it's php4. Is there
          >>>>anyway to tell? Here's the code. It sends me email fine, but when
          >>>>it's on her ISP, it says it sent the mail, but nothing goes through.
          >>>
          >>>
          >>>Look for register_global s and the $_POST array.
          >>
          >>Here is a piece of code I found a long time ago that would extract all of the
          >>get/post'ed variables if register_global s is off. Place this at the top of your
          >>code...
          >>
          > if (!empty($_GET))
          > {
          > extract($_GET);
          > }
          > else if (!empty($HTTP_G ET_VARS))
          > {
          > extract($HTTP_G ET_VARS);
          > }
          >>
          > if (!empty($_POST) )
          > {
          > extract($_POST) ;
          > }
          > else if (!empty($HTTP_P OST_VARS))
          > {
          > extract($HTTP_P OST_VARS);
          > }
          >>
          >>--
          >>Michael Austin.
          >>Database Consultant
          >
          >
          It has to do with the register_global settings in the php.ini file. If you are
          deploying this to multiple servers - I would include it as you really do not
          know what the setting is going to be from server to server [for a given ISP].

          --
          Michael Austin.
          Database Consultant

          Comment

          • Rik

            #6
            Re: PHP email form not working

            Michael Austin wrote:
            alice wrote:
            >Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
            >where this code does not work, is using php 4.4. Should I still try
            >the
            >code your talking about, would it make any difference? We also
            >discovered that other php mail/form code that she had on her ISP that
            >was working the day before, has suddenly stopped working, but we
            >haven't changed anything ourselves.
            >
            It has to do with the register_global settings in the php.ini file.
            If you are deploying this to multiple servers - I would include it as
            you really do not
            know what the setting is going to be from server to server [for a
            given ISP].
            Well, an another script that previously worked suddenly stopped working I
            doubt it.

            I'd suggest the following:
            Make a small script with a hardcoded mail() statement, which sends the mail
            to an emailadress without spam filtering. If this doesn't work, yet mail()
            returns true, contact your hoster. If it does, then try with
            spam-filtering. If that also works, it's the variables in the script that
            are the problem. Try to var_dump them instead of mail()ing , to check what
            value they hold.
            --
            Rik Wasmus


            Comment

            • alice

              #7
              Re: PHP email form not working

              Well now the code has started working again, and we did nothing. I
              guess it was just a problem with the ISP.

              Rik wrote:
              Michael Austin wrote:
              alice wrote:
              Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
              where this code does not work, is using php 4.4. Should I still try
              the
              code your talking about, would it make any difference? We also
              discovered that other php mail/form code that she had on her ISP that
              was working the day before, has suddenly stopped working, but we
              haven't changed anything ourselves.
              It has to do with the register_global settings in the php.ini file.
              If you are deploying this to multiple servers - I would include it as
              you really do not
              know what the setting is going to be from server to server [for a
              given ISP].
              >
              Well, an another script that previously worked suddenly stopped working I
              doubt it.
              >
              I'd suggest the following:
              Make a small script with a hardcoded mail() statement, which sends the mail
              to an emailadress without spam filtering. If this doesn't work, yet mail()
              returns true, contact your hoster. If it does, then try with
              spam-filtering. If that also works, it's the variables in the script that
              are the problem. Try to var_dump them instead of mail()ing , to check what
              value they hold.
              --
              Rik Wasmus

              Comment

              • jiverbean

                #8
                Re: PHP email form not working

                I have a similar problem with a PHP script not sending email. I get an
                error message with a syntax error T_VARIABLE missing in the line where
                the mail() function is.

                TIA

                jiverbean

                aside from my PHP woes, I have some JavaScript issues, but that's
                another story

                Comment

                • jiverbean

                  #9
                  Re: PHP email form not working

                  jiverbean wrote:
                  I have a similar problem with a PHP script not sending email. I get an
                  error message with a syntax error T_VARIABLE missing in the line where
                  the mail() function is.
                  >
                  TIA
                  >
                  jiverbean

                  aside from my PHP woes, I have some JavaScript issues, but that's
                  another story
                  I looked up the PHP manual, and thought the issue was due to the
                  whitespace (tabs, and newlines) in the concatenation of the mail
                  header.

                  There was a semi-colon missing in the statement before the line with
                  the error message.

                  Thanks for your patience,
                  jiverbean

                  Comment

                  Working...