+ Reply to Thread
Results 1 to 5 of 5

Thread: PHP AND HTML Email Script Help

  1. #1
    mattblog's Avatar
    mattblog is offline x10 Lieutenant mattblog is an unknown quantity at this point
    Join Date
    May 2010
    Location
    Ontario,Canada
    Posts
    464

    Exclamation PHP AND HTML Email Script Help

    I made a script to send a email to myself for link exchange. I tried it but it doesnt send the email. can anyone check if i did anything wrong. This was coded in html and refers to an action from a php script.

    Html

    Code:
    <form name="LinkExchange_ContactForm" method="post" action="send_form_email.php">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Request a Link Exchange - Techsavy Technology Forums</title>
    <!-- Mr Bot, Don't Write These Down Please! -->
    <meta name="robots" content="noindex" />
    <!-- Okay, Thanks Bot for Listening -->
    <body style="background-image: url('../../../under_maintenance/bg.gif'); background-repeat: repeat-x">
    </head>
    <!-- BACKGROUND END -->
    <!-- LOGO AND INFORMATION BEGINS-->
    <!-- DO NOT DELETE FOLLOWING TAGS, THEY FORMAT THE INFORMATION BELOW THE HEADER -->
    <br /><br /><br />
    <!-- LOGO -->
    <img alt="" src="../../../under_maintenance/logo.png" align="topleft/" />
    <br /><br /><br />
    <!-- START_FORM -->
    <center>
    <form name="contactform" method="post" action="http://www.techsavy.cz.cc/forms/linkexchange/send_form_email.php">
    <table width="700px">
    <tr>
     <td valign="center">
      <label for="first_name"><h5><font color="#747170">First Name*</font></h5></label>
     </td>
     <td valign="center">
      <input  type="text" name="first_name" maxlength="50" size="30">
     </td>
    </tr>
    <tr>
     <td valign="center">
      <label for="email"><h5><font color="#747170">Email Address*</font></h5></label>
     </td>
     <td valign="center">
      <input  type="text" name="email" maxlength="80" size="30">
     </td>
    </tr>
    <tr>
     <td valign="center"">
      <label for="website"><h5><font color="#747170">Website*</font></h5></label>
     </td>
     <td valign="center">
      <input  type="text" name="website" maxlength="80" size="30">
     </td>
    </tr>
    <tr>
     <td valign="center"">
      <label for="website"><h5><font color="#747170">Your Website Topic*</font></h5></label>
     </td>
     <td valign="center">
      <input  type="text" name="website_topic" maxlength="80" size="30">
     </td>
    </tr>
    <tr>
     <td valign="center"">
      <label for="website"><h5><font color="#747170">Where will my Link be located on your site? *</font></h5></label>
     </td>
     <td valign="center">
      <input  type="text" name="link_place" maxlength="80" size="30">
     </td>
    </tr>
    <tr>
     <td valign="center"">
      <label for="website"><h5><font color="#747170">Title of Your Website*</font></h5></label>
     </td>
     <td valign="center">
      <input  type="text" name="your_link_title" maxlength="80" size="30">
     </td>
    </tr>
     <td valign="center"">
      <label for="website"><h5><font color="#747170">Will My Link be On Every Page of Your Website?*</font></h5></label>
     </td>
     <td valign="center">
      <input  type="checkbox" name="link_every_page" maxlength="100" size="100">
     </td>
    </tr>
     <td valign="center">
      <label for="comments"><h5><font color="#747170">Comments</font></h5></label>
     </td>
     <td valign="center">
      <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
     </td>
    </tr>
    <td>
     <td colspan="2" style="text-align:center">
      <input type="submit" value="Submit">
     </td>
    </tr>
    </table>
    </center>
    <!-- END_FORM -->
    </form>
    </body>
    </html>

    PHP Action Script

    Code:
    <?php
    if(isset($_POST['email'])) {
        $email_to = "hidden for privacy";
        $email_subject = "Link Exchange Request";
    
        
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form your submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }
        
        // validation expected data exists
        if(!isset($_POST['first_name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['website']) ||
            !isset($_POST['website_topic']) ||
            !isset($_POST['link_place']) ||
            !isset($_POST['your_link_title']) ||
            !isset($_POST['link_every_page']) ||
            !isset($_POST['comments'])) {
            died('We are sorry, but there appears to be a problem with the form your submitted.');        
        }
        
        $first_name = $_POST['first_name']; // required
        $email_from = $_POST['email']; // required
        $website = $_POST['website']; // required
            $website_topic = $_POST['website_topic']; // required
            $link_place = $_POST['link_place']; // required
        $your_link_title = $_POST['your_link_title']; // required
        $link_every_page = $_POST['link_every_page']; // required
        $comments = $_POST['comments']; // not required
        
        $error_message = "";
        $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!eregi($email_exp,$email_from)) {
          $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
    
        $error_message = "";
        $website_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!eregi($email_exp,$email_from)) {
          $error_message .= 'The Website you entered does not appear to be valid.<br />';
      }
    
        $string_exp = "^[a-z .'-]+$";
      if(!eregi($string_exp,$first_name)) {
          $error_message .= 'The First Name you entered does not appear to be valid.<br />';
    
      }
      if(strlen($error_message) > 0) {
          died($error_message);
      }
        $email_message = "Form details below.\n\n";
        
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
        
        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Website: ".clean_string($website)."\n";
        $email_message .= "Website Topic: ".clean_string($website_topic)."\n";
        $email_message .= "Link Location: ".clean_string($link_place)."\n";
        $email_message .= "Their Link Title: ".clean_string($your_link_title)."\n";
        $email_message .= "Is The Link on Every Page?: ".clean_string($link_every_page)."\n";
        $email_message .= "Comments ".clean_string($comments)."\n";
    
        
        
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);  
    ?>
    
    Thank you for Submitting your Link Exchange Request. Your Request is Currently Being Processed and You will Receive a Reply Soon!
    <br />
    <a href="http://www.techsavy.cz.cc/">Click Here to Go Back to the Techsavy Homepage</a>
    
    <?
    }
    ?>
    Can anyone check for me?

  2. #2
    AngusThermopyle is offline x10Hosting Member AngusThermopyle is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    84

    Re: PHP AND HTML Email Script Help

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Request a Link Exchange - Techsavy Technology Forums</title>
    <!-- Mr Bot, Don't Write These Down Please! -->
    <meta name="robots" content="noindex" />
    <!-- Okay, Thanks Bot for Listening -->
    </head>
    <body style="background-image: url('../../../under_maintenance/bg.gif'); background-repeat: repeat-x">
    Remove the form tag at the beginning an put the closing head tag before the opening body tag.

    Remove this test:
    PHP Code:
    isset($_POST['link_every_page']) 
    If they do not check that option, nothing is sent and the test will fail. Do you really want that?

    Otherwise, I put it on my account (Chopin) and it sent the email.
    Tried with 'email' field hotmail.com and gmail.com and garbage.com .
    Last edited by AngusThermopyle; 08-02-2010 at 04:52 PM.

  3. #3
    mattblog's Avatar
    mattblog is offline x10 Lieutenant mattblog is an unknown quantity at this point
    Join Date
    May 2010
    Location
    Ontario,Canada
    Posts
    464

    Re: PHP AND HTML Email Script Help

    I dont why, but it did not work for me. I did everything you said and it didnt work.

  4. #4
    bhupendra2895's Avatar
    bhupendra2895 is offline x10 Elder bhupendra2895 is an unknown quantity at this point
    Join Date
    Jun 2010
    Location
    India
    Posts
    554

    Re: PHP AND HTML Email Script Help

    Use preg instead of eregi, because This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
    According to php.net

    PHP Code:
    $email_exp "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!
    eregi($email_exp,$email_from)) {
          
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }

        
    $error_message "";
        
    $website_exp "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!
    eregi($email_exp,$email_from)) {
          
    $error_message .= 'The Website you entered does not appear to be valid.<br />';
      }

        
    $string_exp "^[a-z .'-]+$";
      if(!
    eregi($string_exp,$first_name)) {
          
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';

      } 
    Although I can't solve your mail problem, but use functions which are not going to be deprecated in future.I know your host has php5.2 but who knows in future they can upgrade it or you can have VPS with php 5.3.
    Liked this? Click on the icon on the bottom of post to make me .

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP AND HTML Email Script Help

    How do you know that it's not sending the e-mail, as opposed to the e-mail isn't being received properly?

    Don't ignore errors from functions. Test the return value of mail and output a helpful error message that doesn't reveal too much information.

    To catch other HTML errors (such as c.solomon mentioned), use the W3C's validator. One major syntax problem is you've got extra double-quotes in a number of attributes.

    When posting code, write a minimal test case. It helps you narrow down on the problem and is less cruft for others to wade through.

    To make your code more readable, please indent your code to show nesting level and use [html] tags to colorize the source:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Request a Link Exchange - Techsavy Technology Forums</title>
        <meta name="robots" content="noindex" />
      </head>
      <body style="background-image: url('../../../under_maintenance/bg.gif'); background-repeat: repeat-x">
        <form name="contactform" method="post" action="http://www.techsavy.cz.cc/forms/linkexchange/send_form_email.php">
            <label for="first_name">First Name*</label>
            <input  name="first_name" maxlength="50" size="30">
    Don't use HTML elements for formatting, as you do with <br/>, <h5>, <font> and others. HTML defines the structure of a document, not how it's presented. Use CSS for styling. <h5> is used to mark a heading. <font>, <center> and <br> are presentational elements and should be avoided. Along the same lines, don't use tables for layout. There are plenty of ways of styling forms without using tables ("Applying CSS to forms", "Fancy Form Design Using CSS").

    Don't use die when outputting HTML. It will result in invalid HTML.

    If you find yourself repeatedly writing very similar code, you should abstract it into a function or rewrite it as a loop or switch. Here, you could make better use of both functions and loops.
    Last edited by misson; 08-03-2010 at 02:59 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. PHP script within Html or htm
    By timmy09 in forum Programming Help
    Replies: 2
    Last Post: 10-02-2010, 02:09 PM
  2. [REQ] HTML Template integrate to a script
    By Jesse in forum The Marketplace
    Replies: 1
    Last Post: 05-26-2010, 09:17 PM
  3. RSS to HTML PHP Script (FREE)
    By unmanaged in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 02-21-2008, 04:44 PM
  4. Including PHP script in HTML
    By chrisv in forum Free Hosting
    Replies: 7
    Last Post: 08-31-2007, 08:10 PM
  5. HTML Tester Script...
    By Fedlerner in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 09-28-2006, 09:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers