Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post

    form to email problem

    hey people, i have this order form for a website which would send the results to an email address. for some reason it does not seem to be working the php coding is shown below:

    PHP Code:

    <?php
    $to 
    "razzyc@hotmail.co.uk";//<== update the email address
    $email_subject "New Form submission";
    $email_body "You have received a new message from the user $first_name.\n".
        


    $first_name $_REQUEST['first_name'] ;
    $last_name $_REQUEST['last_name'] ;
    $first_line_address $_REQUEST['address'] ;
    $post_code $_REQUEST['postcode'] ;
    $tel_number $_REQUEST['tel_no'] ;
    $email_address $_REQUEST['email'] ;


    function 
    isInjected($str) {
        
    $injections = array('(\n+)',
        
    '(\r+)',
        
    '(\t+)',
        
    '(%0A+)',
        
    '(%0D+)',
        
    '(%08+)',
        
    '(%09+)'
        
    );
        
    $inject join('|'$injections);
        
    $inject "/$inject/i";
        if(
    preg_match($inject,$str)) {
            return 
    true;
        }
        else {
            return 
    false;
        }
    }

    ?>

    and the coding for the form is:

    Code:
    <form name="order" method="post" id="orderForm" action="test23.php">
    
    		
    1. First Name: <input type="text" name="first_name" />
    <br/>   
    2. Last Name: <input type="text" name="last_name"  />
    <br/>
    3. Firstline Address: <input type="text" name="address"/> 
    <br/>
     4. Post Code: <input type="text" name="postcode"/>
    <br/> 
     5. Telephone No: <input type="text" name="tel_no"/>
    <br/> 
     6. Email Address: </td>  <td><input type="email" name="email"/> 
    <br/>
    </form>
    would really appreciate it if someone could help

    thank you

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Your code doesn't include the mail() method to actually send the email
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,455
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    Use Google to find a PHP example for: PHP contact form email

    You're missing a lot of things ... including the mail() function itself.

  • #4
    New to the CF scene
    Join Date
    Jul 2012
    Location
    London
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Just to add... in case the email address you are sending from requires authentication, I would suggest you look up on google phpmailer.

    This is a class that will allow you to send emails through servers that require authentication.

  • #5
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    hey people, thank you for that, i have made some changes to it, but for some reason and error message comes up.(internal server error)

    the php code is as follows:

    PHP Code:

    $webmaster_email 
    "musharof@al-rahmah.co.uk";


    $first_name $_REQUEST['first_name'] ;
    $last_name $_REQUEST['last_name'] ;
    $email_address $_REQUEST['email'] ;



    function 
    isInjected($str) {
        
    $injections = array('(\n+)',
        
    '(\r+)',
        
    '(\t+)',
        
    '(%0A+)',
        
    '(%0D+)',
        
    '(%08+)',
        
    '(%09+)'
        
    );
        
    $inject join('|'$injections);
        
    $inject "/$inject/i";
        if(
    preg_match($inject,$str)) {
            return 
    true;
        }
        else {
            return 
    false;
        }
    }


    else {
    mail"$webmaster_email""Feedback Form Results",
      
    $first_name"From: $email_address" );
    header"thankyou" );
    }
    ?> 

    i have not finished it yet so please ignore that fact that there is not authentication etc


    thank you

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Do you have a mail server running?
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #7
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    sorry andrew it is working now, i get an email sent to the email address as soon as i click the submit button, however i have a new problem now

    i am trying to output the results on the email body so that the filled in fields will appear as follows:

    first name: blahblah
    last name: blahblahblah
    first line address: 123 new street

    i have used the following codes however it does not seem to work

    PHP Code:
    <?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email

      
    {


      
    //send email
      
    $email $_REQUEST['email'] ;
      
    mail("musharof@al-rahmah.co.uk""Feedback Form Results",
      
    "From:" $email,

    First name: <?php echo $_POST["first_name"]; ?>
    Last name: <?php echo $_POST["last_name"]; ?>
    Address: <?php echo $_POST["address"]; ?>

      echo "Thank you for using our mail form";
      }

    ?>

  • #8
    New Coder
    Join Date
    Aug 2012
    Location
    Finland
    Posts
    23
    Thanks
    2
    Thanked 5 Times in 5 Posts
    You should try this:
    PHP Code:
    <?php 
    if (isset($_REQUEST['email'])) 
    //if "email" is filled out, send email 

      



      
    //send email 
      
    $to "musharof@al-rahmah.co.uk";
      
    $subject "Emails subject here";
      
    $email $_REQUEST['email'] ; 

      
    // To allow HTML codes to email!
      
    $headers  'MIME-Version: 1.0' "\r\n";
      
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

      
    $message "
      <html>
      <head><title>Emails subject here</title></head>
      <body>
      <p>Email is from "
    .$email." </p>
      <p>First name: "
    .$_POST["first_name"]."<br />
       Last name: "
    .$_POST["last_name"]."<br />
       Address: "
    .$_POST["address"]."</p>
       </body>
       </html>"
    ;

      
    mail($to,$subject,$message,$headers);

      echo 
    "Thank you for using our mail form"
      } 

    ?>
    EDIT: You should read this; PHP: mail -Manual
    Should working well, report if get errors
    Last edited by ECoode; 08-02-2012 at 12:38 PM. Reason: added link!

  • Users who have thanked ECoode for this post:

    Razzy (08-02-2012)

  • #9
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    hey ecoode thanx for that it worked apart from a small problem, for some reason the senders email address does not appear on the "from" section on the email.

    i added......"From:" . $email........ within mail() but it still doesnt work

    as you can see below:

    PHP Code:

    <?php 
    if (isset($_REQUEST['email'])) 
    //if "email" is filled out, send email 

      



      
    //send email 
      
    $to "musharof@al-rahmah.co.uk";
      
    $subject "order form submitted";
     
    $email $_REQUEST['email'] ; 

      
    // To allow HTML codes to email!
      
    $headers  'MIME-Version: 1.0' "\r\n";
      
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

      
    $message "
      <html>
      <head><title>Order placed</title></head>
      <body>
      <p>Email is from "
    .$email." </p>
      <p>First name: "
    .$_POST["first_name"]."<br />
       Last name: "
    .$_POST["last_name"]."<br />
       Address: "
    .$_POST["address"]."</p>
       </body>
       </html>"
    ;

      
    mail($to,$subject,$message,$headers, [B"From:" $email[/B]);

      echo 
    "Thank you for using our mail form"
      } 

    ?>

  • #10
    New Coder
    Join Date
    Aug 2012
    Location
    Finland
    Posts
    23
    Thanks
    2
    Thanked 5 Times in 5 Posts
    You should use my original code, as you might noticed that I added part:
    PHP Code:
    <p>Email is from ".$email." </p
    to $message variable to show on every email who sended it.

    If you still wanna add that 'From' part you can add this
    PHP Code:
    $headers .= 'From: $email' "\r\n"
    and change mail function back to where it was.

  • Users who have thanked ECoode for this post:

    Razzy (08-03-2012)

  • #11
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    thanks ecoode i used

    Code:
    $headers .= 'From: $email' . "\r\n";
    but still with no success...for some reason on the "from" field of the email, i get random email address such as: From: "$email"@boscgi3406.eigbox.net

    but anyhow i have decided to just use the code that you first gave me

    thank you very much

  • #12
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Variables do not expand within single quotes, nor do escaped characters:

    PHP Code:
    $headers .= "From: $email\r\n"
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Razzy (08-03-2012)

  • #13
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    thank you very much andrewGSW it perfectly works now


  •  

    Posting Permissions

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