Results 1 to 3 of 3

Thread: I Need Help With PHP Email Code For Web Site

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I Need Help With PHP Email Code For Web Site

    Hi, I would appreciate if some of you on here can help me out. I enjoyed this web site, and the forums. I am helping to create a web site for Non Profit Group, and the web site is here http://www.missionariesofhopeinc.com/ . On the left hand side of the page I am trying to get visitors to sign up for a mailing list. I am new at PHP , and the site is hosted at GoDaddy. I was wondering if any of you can look at the code, and give me pointers and show me how it should be done. I would like the information to be sent to missionariesofhopeinc@hotmail.com , when the user submits it.

    Thanks in advance, I will check back and forth during the day or days to come.

    Index Code Below:
    Code:
    <form action="mail.php" method="POST"><b>First Name:</b><br><input 
    
    type="text" name="firstname" size=24 maxlength="24"/><br><b>Last 
    
    Name:</b><br><input type="text" name="lastname" size=24 
    
    maxlength="24"/><br><b>Email:</b><br><input type="text" name="email" 
    
    size=24 maxlength="70"/></textarea><br><input type="submit" value="Join 
    
    Mailing List">


    PHP Code Below:
    Code:
    <?php
    
    /* All form fields are automatically passed to the PHP script through the 
    
    array $HTTP_POST_VARS. */
    $firstname = $HTTP_POST_VARS['firstname'];
    $lastname = $HTTP_POST_VARS['lastname'];
    $email = $HTTP_POST_VARS['email'];
    
    /* PHP form validation: the script checks that the Email field contains a 
    
    valid email address and the Subject field isn't empty. preg_match 
    
    performs a regular expression match. It's a very powerful PHP function to 
    
    validate form fields and other strings - see PHP manual for details. */
    if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email = 
    
    'missionariesofhopeinc@hotmail.com')) {
      echo "<h4>Invalid email address</h4>";
      echo "<a href='javascript:history.back(1);'>Back</a>";
    } elseif ($subject == "") {
      echo "<h4>No subject</h4>";
      echo "<a href='javascript:history.back(1);'>Back</a>";
    }
    
    /* Sends the mail and outputs the "Thank you" string if the mail is 
    
    successfully sent, or the error string otherwise. */
    elseif (mail($firstname,$lastname,$email = 
    
    'missionariesofhopeinc@hotmail.com)) {
      echo "<h4>Thank you for sending email</h4>";
    } else {
      echo "<h4>Can't send email to $email = 
    
    'missionariesofhopeinc@hotmail.com</h4>";
    }
    ?>

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    What does this produces errors, nothing, a mix?

    First try changing your html. You didn't have a text area at all if you want one you need to open it with <textarea> then close it </textarea> don't open it with an input.

    Code:
    <form action="mail.php" method="POST">
    <strong>First Name:</strong>
    <br />
    <input type="text" name="firstname" size="24" maxlength="24" />
    <br />
    <strong>Last Name:</strong>
    <br />
    <input type="text" name="lastname" size="24" maxlength="24" />
    <br />
    <strong>Email:</strong>
    <br />
    <input type="text" name="email" size="24" maxlength="70" />
    <br />
    <input type="submit" value="Join Mailing List" />
    </form>

  3. The Following User Says Thank You to bluewalrus For This Useful Post:

    MOHinc (07-01-2009)

  4. #3
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I inserted the Text Area html code, and all it did was mess up the rest of my Html. It would appear in the text fields where you would input the information, or when I placed it in other areas it messed up with it as well. If you could show me where to place it, that would be a big help. I understand if your busy, and I do appreciate your advice. I think its the PHP code, because when I hit submit this message comes up "Parse error: syntax error, unexpected T_STRING in /home/content/m/o/h/mohinc/html/mail.php on line 24" , its driving me crazy.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •