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 8 of 8
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    78
    Thanks
    19
    Thanked 1 Time in 1 Post

    Thumbs up PHP Form to Mail Help

    ok friends i created my form and am not good at php and one can help me make a php form basing on my form i created on my site please?

    This is Markup

    <div class="Welcome">
    <h2>Contact Form</h2>
    <p><strong>Looking for a Designer ? Send me your details right now!!. </strong></p>
    <div class="bg"></div>
    <form action="contact.php" method="post" name="contactform" id="contactform">
    <ol>
    <li>
    <label for="name">your name <span class="red">*</span></label>
    <input id="name" name="name" class="text" />
    </li>
    <li>
    <label for="email">Your email <span class="red">*</span></label>
    <input id="email" name="email" class="text" />
    </li>
    <li>
    <label for="company">Company Name</label>
    <input id="company" name="company" class="text" />
    </li>
    <li>
    <label for="subject">Subject</label>
    <input id="subject" name="subject" class="text" />
    </li>
    <li>
    <label for="message">message <span class="red">*</span></label>
    <textarea id="message" name="message" rows="6" cols="50"></textarea>
    </li>
    <li class="buttons">
    <input type="image" name="imageField" id="imageField" src="images/send.gif" />
    </li>
    <li class="buttons"></li>
    </ol>
    </form>
    </div>
    This is php

    Code:
    <?php
    
    if(!$_POST) exit;
    
    $email = $_POST['email'];
    
    
    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    $error.="Invalid email address entered";
    $errors=1;
    }
    if($errors==1) echo $error;
    else{
    $values = array ('name','email','message');
    $required = array('name','email','message');
    
    $your_email = "zo_ee_20@hotmail.com";
    $email_subject = "New Message: ".$_POST['subject'];
    $email_content = "new message:\n";
    
    foreach($values as $key => $value){
    if(in_array($value,$required)){
    if ($key != 'subject' && $key != 'company') {
    if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
    }
    $email_content .= $value.': '.$_POST[$value]."\n";
    }
    }
    
    if(@mail($your_email,$email_subject,$email_content)) {
    echo 'Message sent!';
    } else {
    echo 'ERROR!';
    }
    }
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,855
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    ok friends i created my form and am not good at php and one can help me make a php form basing on my form i created on my site please?
    Could you please specify the problem that you are facing?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    78
    Thanks
    19
    Thanked 1 Time in 1 Post

    Thumbs down

    Quote Originally Posted by abduraooft View Post
    Could you please specify the problem that you are facing?
    Form is not processing at all . Please help me . Am not good at php. sems some thing wrong with my php

  • #4
    New Coder
    Join Date
    Feb 2009
    Posts
    78
    Thanks
    19
    Thanked 1 Time in 1 Post
    sorry for the bump. Any help please?
    Last edited by zoe20; 01-23-2010 at 11:29 AM.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,855
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by zoe20 View Post
    Form is not processing at all . Please help me . Am not good at php. sems some thing wrong with my php
    I'm sorry to say that the answer is still vague. What is not processing - the validation part or the mail sending part?

    It gives me the message
    Invalid email address entered
    when I tried that code at my end without filling anything int hat form.

    PS:
    PHP Code:
    if(!$_POST) exit; 
    A better approach is
    PHP Code:
    if(isset($_POST)){
     
    // process the submitted data here

    }
    else {
    // do something if required

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New Coder
    Join Date
    Feb 2009
    Posts
    78
    Thanks
    19
    Thanked 1 Time in 1 Post
    ok i changed my code.i tested it and i am getting mails to my root e-mail.But surprisingly am getting mails from like this : myemail@kiwi.cryl.net instead of myemail@hotmail.com. Some thing wrong with the script??

    <?php

    if (!$_POST) {
    exit();
    }

    $email = $_POST['email'];


    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if (!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" . "@" . "([a-z0-9]+([\.-][a-z0-9]+)*)+" .
    "\\.[a-z]{2,}" . "$", $email)) {
    $error .= "Invalid email address entered";
    $errors = 1;
    }
    if ($errors == 1) {
    echo $error;
    } else {
    $values = array('name', 'email', 'message');
    $required = array('name', 'email', 'message');

    $your_email = "zo_ee_20@hotmail.com";
    $email_subject = "New Message: " . $_POST['subject'];
    $email_content = "new message:\n";

    foreach ($values as $key => $value) {
    if (in_array($value, $required)) {
    if ($key != 'subject' && $key != 'company') {
    if (empty($_POST[$value])) {
    echo 'PLEASE FILL IN REQUIRED FIELDS';
    exit;
    }
    }
    $email_content .= $value . ': ' . $_POST[$value] . "\n";
    }
    }

    if (@mail($your_email, $email_subject, $email_content)) {
    echo 'Message sent!';
    } else {
    echo 'ERROR!';
    }
    }
    ?>
    Last edited by zoe20; 01-24-2010 at 05:36 PM.

  • #7
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dreamtemplate

    zoe,
    I got the same php coding but can't get it to work either.
    have you fixed the problem?
    thanks

  • #8
    New Coder
    Join Date
    Feb 2009
    Posts
    78
    Thanks
    19
    Thanked 1 Time in 1 Post

    Unhappy

    Quote Originally Posted by tchot View Post
    zoe,
    I got the same php coding but can't get it to work either.
    have you fixed the problem?
    thanks
    Yes my form is processing but the problem i mentioned in my earlier post still persisting. Me getting mails like this myemail@myemail@kiwi.cryl.net instead of myemail@hotmail.com. .net instead of myemail@hotmail.com. I dont know what is this kiwi.cryl is all about. seems some thing wrong in my php. Need some experts to solve my problem.


  •  

    Posting Permissions

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