+ Reply to Thread
Results 1 to 9 of 9

Thread: php mail script

  1. #1
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member droctoganapus86 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    49

    php mail script

    hello,

    I have a contact/email form made powered with php, and i'd like to have some extra things added. But i dont know anything about php, so who would like to help me?

    the extra's are email attachment and maybe checkboxes so you can select one or more. also, if you can find something to prevent "flooding" (pressing the button 100 times) that would be nice.
    I have this script :

    Code:
    <?php
    session_start();
    $mail=' '; //je email
    include('validEmail.php');
    if($_POST['send']){
    	if(!validEmail($_POST['mail'])){
    		$_SESSION['message']='Please fill in a correct Email-adress.';
    	}
    	elseif(trim($_POST['name'])==""){
    		$_SESSION['message']='Please fill in your name.';
    	}
    	elseif(trim($_POST['message'])==""){
    		$_SESSION['message']='Please type your message.';
    	}
    	else{
    		$_SESSION['message']='Thanks, your message has been send.';
    	}
    	mail($mail,'Bericht van: '.trim($_POST['name']),$_POST['message'],'From: '.trim($_POST['name']).' <'.$_POST['mail'].'>');
    }
    ?>
    Code:
    <form action="#" method="post">
    	<label for="name">Name :</label><br />
    	<input class="info" type="text" value="<?php echo($_POST['name'])?$_POST['name']:'';?>" name="name" id="name" />
    	<label for="mail">E-mail :</label><br />
    	<input class="info" type="text" value="<?php echo($_POST['mail'])?$_POST['mail']:'';?>" name="mail" id="mail" />
    	<label for="message">Message :</label><br />
    	<textarea class="info" name="message" id="message" cols="" rows="5" ><?php echo($_POST['message'])?$_POST['message']:'';?></textarea>
    	<div><input class="send" type="submit" value="Send" name="send" /></div>
    </form>
    Last edited by droctoganapus86; 12-16-2010 at 04:28 PM.

  2. #2
    threedee's Avatar
    threedee is offline x10Hosting Member threedee is an unknown quantity at this point
    Join Date
    Jun 2008
    Location
    Devil's Lair
    Posts
    28

    Re: php mail script

    Just wondering,

    include('validEmail.php');

    what is inside your validEmail.php? Or did I miss seeing that part here?
    Muahahahahahaha.
    --------------------------
    Some Free IRC Unix Stuff

  3. #3
    lichao891069 is offline x10Hosting Member lichao891069 is an unknown quantity at this point
    Join Date
    Aug 2010
    Posts
    4

    Re: php mail script

    Quote Originally Posted by droctoganapus86 View Post
    hello,

    I have a contact/email form made powered with php, and i'd like to have some extra things added. But i dont know anything about php, so who would like to help me?

    the extra's are email attachment and maybe checkboxes so you can select one or more. also, if you can find something to prevent "flooding" (pressing the button 100 times) that would be nice.
    I have this script :

    Code:
    <?php
    session_start();
    $mail=' '; //je email
    include('validEmail.php');
    if($_POST['send']){
        if(!validEmail($_POST['mail'])){
            $_SESSION['message']='Please fill in a correct Email-adress.';
        }
        elseif(trim($_POST['name'])==""){
            $_SESSION['message']='Please fill in your name.';
        }
        elseif(trim($_POST['message'])==""){
            $_SESSION['message']='Please type your message.';
        }
        else{
            $_SESSION['message']='Thanks, your message has been send.';
        }
        mail($mail,'Bericht van: '.trim($_POST['name']),$_POST['message'],'From: '.trim($_POST['name']).' <'.$_POST['mail'].'>');
    }
    ?>
    Code:
    <form action="#" method="post">
        <label for="name">Name :</label><br />
        <input class="info" type="text" value="<?php echo($_POST['name'])?$_POST['name']:'';?>" name="name" id="name" />
        <label for="mail">E-mail :</label><br />
        <input class="info" type="text" value="<?php echo($_POST['mail'])?$_POST['mail']:'';?>" name="mail" id="mail" />
        <label for="message">Message :</label><br />
        <textarea class="info" name="message" id="message" cols="" rows="5" ><?php echo($_POST['message'])?$_POST['message']:'';?></textarea>
        <div><input class="send" type="submit" value="Send" name="send" /></div>
    </form>
    absolutely

  4. #4
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member droctoganapus86 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    49

    Re: php mail script

    that's a script to validate email adresses. it checks some common mistakes, and then looks it up in the dns. or something, thats what they told me :P

  5. #5
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member droctoganapus86 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    49

    Re: php mail script

    anyone who cangive me a hint?

  6. #6
    rajat44 is offline Banned rajat44 is an unknown quantity at this point
    Join Date
    Oct 2010
    Posts
    24

    Re: php mail script

    its very easy!

    <?php
    // Contact subject
    $subject ="Enter subject here";
    // Details
    $message="";

    // Mail of sender
    $mail_from=$_POST['mail'];
    // From
    $header="from: $name <$mail_from>";

    // Enter your email address
    $to ='someone@somewhere.com';

    $send_contact=mail($to,$subject,$message,$header);

    // Check, if message sent to your email
    // display message "We've recived your information"
    if($send_contact){
    echo "We've recived your mail";
    }
    else {
    echo "ERROR";
    }
    ?>
    you can get those variables from a form. for example, the email from part of the code.
    in your html form in ur post, the email text fields 'name' is mail.

    so, here- $mail_from=$_POST['mail'];

    hope it helped.

  7. #7
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member droctoganapus86 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    49

    Re: php mail script

    i already have that part
    what I wanted for extra is file attachment

  8. #8
    rajat44 is offline Banned rajat44 is an unknown quantity at this point
    Join Date
    Oct 2010
    Posts
    24

    Re: php mail script

    <form method="POST" name="email_form_with_php"
    action="php-form-action.php" enctype="multipart/form-data">

    <label for='name'>Name: </label>
    <input type="text" name="name" >

    <label for='email'>Email: </label>
    <input type="text" name="email" >

    <label for='message'>Message:</label>
    <textarea name="message"></textarea>

    <label for='uploaded_file'>Select A File To Upload:</label>
    <input type="file" name="uploaded_file">

    <input type="submit" value="Submit" name='submit'>
    </form>

    the form will be something like this^


    Now to get the uploaded file in the script:

    //Get the uploaded file information
    $name_of_uploaded_file =
    basename($_FILES['uploaded_file']['name']);

    //get the file extension of the file
    $type_of_uploaded_file =
    substr($name_of_uploaded_file,
    strrpos($name_of_uploaded_file, '.') + 1);

    $size_of_uploaded_file =
    $_FILES["uploaded_file"]["size"]/1024;//size in KBs
    The code above is getting the different attributes of the uploaded file from the $_FILES array.



    Now, to validate file size:

    //Settings
    $max_allowed_file_size = 100; // size in KB
    $allowed_extensions = array("jpg", "jpeg", "gif", "bmp");

    //Validations
    if($size_of_uploaded_file > $max_allowed_file_size )
    {
    $errors .= "\n Size of file should be less than $max_allowed_file_size";
    }

    //------ Validate the file extension -----
    $allowed_ext = false;
    for($i=0; $i<sizeof($allowed_extensions); $i++)
    {
    if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
    {
    $allowed_ext = true;
    }
    }

    if(!$allowed_ext)
    {
    $errors .= "\n The uploaded file is not supported file type. ".
    " Only the following file types are supported: ".implode(',',$allowed_extensions);
    }

    copying the file to an uploads folder:

    //copy the temp. uploaded file to uploads folder
    $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
    $tmp_path = $_FILES["uploaded_file"]["tmp_name"];

    if(is_uploaded_file($tmp_path))
    {
    if(!copy($tmp_path,$path_of_uploaded_file))
    {
    $errors .= '\n error while copying the uploaded file';
    }
    }


    and now, the mail-

    $message = new Mail_mime();
    $message->setTXTBody($text);
    $message->addAttachment($path_of_uploaded_file);
    $body = $message->get();
    $extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
    $headers = $message->headers($extraheaders);
    $mail = Mail::factory("mail");
    $mail->send($to, $headers, $body);

  9. #9
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member droctoganapus86 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    49

    Re: php mail script

    thank you very much

+ Reply to Thread

Similar Threads

  1. Cannot send mail from perl script
    By ldsdates in forum Free Hosting
    Replies: 3
    Last Post: 06-11-2010, 02:11 AM
  2. e-mail form through php script
    By ajnv60 in forum Programming Help
    Replies: 2
    Last Post: 05-24-2010, 03:43 PM
  3. Mail using script
    By mrxp_anupam in forum Free Hosting
    Replies: 1
    Last Post: 10-19-2008, 09:18 AM
  4. foward mail to a php script
    By ruicos in forum Programming Help
    Replies: 3
    Last Post: 09-13-2008, 07:55 AM
  5. Send Mail Script
    By james3uk in forum Programming Help
    Replies: 3
    Last Post: 04-01-2008, 05:36 AM

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