SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form not sending emails

    This script is sending me to the correct page once I submit but I dont receive the email and I am not sure why. The script works with my other website.

    Anyone have any ideas?


    PHP Code:
    <?php

    if(isset($_POST['Email_Address'])) {
        
        
        if(
    $email_to == "youremailaddress@yourdomain.com") {
            die(
    "This message is for the Webmaster. Please enter your email address");
        }
        
        function 
    died($error) {
            echo 
    "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();
        }
        
        if(!isset(
    $_POST['Full_Name']) ||
            !isset(
    $_POST['Email_Address']) ||
            !isset(
    $_POST['Telephone_Number']) ||
            !isset(
    $_POST['Your_Message'])) {
            
    died('We are sorry, but there appears to be a problem with the form your submitted.');        
        }
        
    $email_to "myemail@yahoo.com"// your email address
        
    $email_subject "Mylubbock Form"// email subject line
        
    $thankyou "index.html"// thank you page
        
        
    $full_name $_POST['Full_Name']; // required
        
    $email_from $_POST['Email_Address']; // required
        
    $telephone $_POST['Telephone_Number']; // not required
        
    $comments $_POST['Your_Message']; // 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 />';
      }
      if(
    strlen($full_name) < 2) {
          
    $error_message .= 'Your Name does not appear to be valid.<br />';
      }
      if(
    strlen($comments) < 2) {
          
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
      
      if(
    strlen($error_message) > 0) {
          
    died($error_message);
      }
        
    $email_message "Form details below.\r\n";
        
        function 
    clean_string($string) {
          
    $bad = array("content-type","bcc:","to:","cc:","href");
          return 
    str_replace($bad,"",$string);
        }
        
        
    $email_message .= "Full Name: ".clean_string($full_name)."\r\n";
        
    $email_message .= "Email: ".clean_string($email_from)."\r\n";
        
    $email_message .= "Telephone: ".clean_string($telephone)."\r\n";
        
    $email_message .= "Message: ".clean_string($comments)."\r\n";
        
    $headers 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' phpversion();
    @
    mail($email_to$email_subject$email_message$headers);
    header("Location: $thankyou");
    ?>
    <script>location.replace('<?php echo $thankyou;?>')</script>
    <?
    }
    ?>
    MY FORM:
    HTML Code:
    <form id="contactform" action="contact.php" method="post" ><!--id=contactform-->
              <ol>
                <li>
                  <label for="Full_Name">First Name <span class="red">*</span></label>
                  <input id="Full_Name" name="Full_Name" class="text" />
                </li>
                <li>
                  <label for="Email_Address">Your email <span class="red">*</span></label>
                  <input id="Email_Address" name="Email_Address" class="text" />
                </li>
                <li>
                  <label for="company">Company</label>
                  <input id="company" name="company" class="text" />
                </li>
                <li>
                  <label for="Telephone_Number">Phone #</label>
                  <input id="Telephone_Number" name="Telephone_Number" class="text" />
                </li>
                <li>
                  <label for="Your_Message">Message <span class="red">*</span></label>
                  <textarea id="Your_Message" name="Your_Message" rows="6" cols="50"></textarea>
                </li>
                <input name="submit" type="submit" value="Send" />

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, you just need to do some basic debugging

    1) start at the top of the script as specified in your form's action attribute and add

    Code:
     
    echo 'got here'; die();
    2) run your form to check if it gets to your php script

    3) then move the above echo/die down, line by line if you have to, and add appropriate echo statements to display values of variables and then run the form again each time you move the echos.

    4) as part of 3) insert the echos in each part of conditional blocks (IF blocks) to check your code logic is correct

    keep doing this until your echos show something is not right. then back track your code to fix the error.

    5) keep repeating 3) and 4) until you get to the end of your script and it works ok.

    if you have a debugger, then debugguing will be easier as you can set break points and check values of variables which is essentially what the above steps are doing.

  3. #3
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    do an extremely basic test mail();


    http://us3.php.net/manual/en/function.mail.php
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.


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
  •