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 9 of 9

Thread: email

  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts

    email

    is it possible to use the emailfrom into $to? my code is not working properly i cant receive any email see this code..

    PHP Code:

    $to 
    '$emailfrom';
    $subject trim($_POST['subject']);
    $emailfrom trim($_POST['emailfrom']); 

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    you have to actually use the mail function..

    mail('caffeinated@example.com', 'My Subject', $message);
    first parameter is recipient, second subject, 3rd message, 4th header.

    you can put "-fyouremail" in the header parameter.

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts
    no actually the recipient address is dynamic it will depends on the input text of the user.. so when i type the email address in the input box it will send automatically to his email

  • #4
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    yes that is fine..

    $recipient = $_POST['whatever'];

    then you can just do mail($recipient[...]

  • The Following 2 Users Say Thank You to Adee For This Useful Post:

    kool man (11-22-2011), scott_white85 (11-22-2011)

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts
    i actually do that.. this is the whole php code

    PHP Code:
    // prints form
    function print_form(){
    ?>
    <p><span class="required">*</span> Required fields</p>
        <form method="post" action="<?php echo $_SERVER[’PHP_SELF’];?>" id="uploadform" enctype="multipart/form-data">
        <p><label for="emailfrom">Email <span class="required">*</span></label>
        <input name="emailfrom" id="emailfrom" type="text" class="field" value="<?= $_SESSION['myForm']['emailfrom']; ?>" tabindex="3"/></p>
        
        
        
        <p><label for="subject">Subject <span class="required">*</span></label>
        <input name="subject" id="subject" type="text" class="field" value="<?= $_SESSION['myForm']['subject']; ?>" tabindex="5"/></p>
        
        
        
        <p><label for="attachment">File Upload<br />(1 file only, max file size 1024kb. Allowed file formats are .doc, .pdf, .zip, .rar)</label>
        <input name="attachment" id="attachment" type="file" tabindex="7">
        
        <p><input type="submit" name="submit" id="submit" value="Send Email!"  tabindex="8"/></p>
        <p><input type="hidden" name="submitted"  value="true" /></p>
        </form>
    <?php
    }

    // enquiry form validation

    function process_form() {
        
    // Read POST request params into global vars
        // FILL IN YOUR EMAIL
        
        
        
        
    $to $emailfrom;
        
        
    $subject trim($_POST['subject']);
        
        
        
    $emailfrom trim($_POST['emailfrom']);
        
        
        
        
        
        
    // Allowed file types. add file extensions WITHOUT the dot.
        
    $allowtypes=array("zip""rar""doc""pdf");
        
        
    // Require a file to be attached: false = Do not allow attachments true = allow only 1 file to be attached
        
    $requirefile="true";
        
        
    // Maximum file size for attachments in KB NOT Bytes for simplicity. MAKE SURE your php.ini can handel it,
        // post_max_size, upload_max_filesize, file_uploads, max_execution_time!
        // 2048kb = 2MB,       1024kb = 1MB,     512kb = 1/2MB etc..
        
    $max_file_size="1024";
        
        
    // Thank you message
        
    $thanksmessage="Your email has been sent, we will respond shortly.";

        
    $errors = array(); //Initialize error array

        

        //checks for an email
        
    if (empty($_POST['emailfrom']) ) {
            
    $errors[]='You forgot to enter your email';
            } else {

            if (!
    eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$'stripslashes(trim($_POST['emailfrom'])))) {
                
    $errors[]='Please enter a valid email address';
            } 
    // if eregi
        
    // if empty email

        //checks for a subject
        
    if (empty($_POST['subject']) ) {
            
    $errors[]='You forgot to enter a subject';
            }

        
    //checks for a message

            
         // checks for required file
        // http://amiworks.co.in/talk/handling-file-uploads-in-php/
        
    if($requirefile=="true") {
            if(
    $_FILES['attachment']['error']==4) {
                
    $errors[]='You forgot to attach a file';
            }
        }
            
        
    //checks attachment file
        // checks that we have a file
        
    if((!empty($_FILES["attachment"])) && ($_FILES['attachment']['error'] == 0)) {
                
    // basename -- Returns filename component of path
                
    $filename basename($_FILES['attachment']['name']);
                
    $ext substr($filenamestrrpos($filename'.') + 1);
                
    $filesize=$_FILES['attachment']['size'];
                
    $max_bytes=$max_file_size*1024;
                
                
    //Check if the file type uploaded is a valid file type. 
                
    if (!in_array($ext$allowtypes)) {
                    
    $errors[]="Invalid extension for your file: <strong>".$filename."</strong>";
                    
            
    // check the size of each file
            
    } elseif($filesize $max_bytes) {
                    
    $errors[]= "Your file: <strong>".$filename."</strong> is to big. Max file size is ".$max_file_size."kb.";
                }
                
        } 
    // if !empty FILES

        
    if (empty($errors)) { //If everything is OK
            
            // send an email
            // Obtain file upload vars
            
    $fileatt      $_FILES['attachment']['tmp_name'];
            
    $fileatt_type $_FILES['attachment']['type'];
            
    $fileatt_name $_FILES['attachment']['name'];
            
            
    // Headers
            
    $headers "From: $emailfrom";
            
            
    // create a boundary string. It must be unique
              
    $semi_rand md5(time());
              
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";

              
    // Add the headers for a file attachment
              
    $headers .= "\nMIME-Version: 1.0\n" .
                          
    "Content-Type: multipart/mixed;\n" .
                          
    " boundary=\"{$mime_boundary}\"";

              
    // Add a multipart boundary above the plain message
              
    $message ="This is a multi-part message in MIME format.\n\n";
              
    $message.="--{$mime_boundary}\n";
              
    $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
              
    $message.="Content-Transfer-Encoding: 7bit\n\n";
             
            if (
    is_uploaded_file($fileatt)) {
              
    // Read the file to be attached ('rb' = read binary)
              
    $file fopen($fileatt,'rb');
              
    $data fread($file,filesize($fileatt));
              
    fclose($file);
              
              
              

              
    // Base64 encode the file data
              
    $data chunk_split(base64_encode($data));

              
    // Add file attachment to the message
              
    $message .= "--{$mime_boundary}\n" .
                          
    "Content-Type: {$fileatt_type};\n" .
                          
    " name=\"{$fileatt_name}\"\n" .
                          
    //"Content-Disposition: attachment;\n" .
                          //" filename=\"{$fileatt_name}\"\n" .
                          
    "Content-Transfer-Encoding: base64\n\n" .
                          
    $data "\n\n" .
                          
    "--{$mime_boundary}--\n";
            }
            
            
            
    // Send the completed message
            
            
    $envs = array("HTTP_USER_AGENT""REMOTE_ADDR""REMOTE_HOST");
            foreach (
    $envs as $env)
            
    $message .= "$env: $_SERVER[$env]\n";
            
            if(!
    mail($to,$subject,$message,$headers)) {
                exit(
    "Mail could not be sent. Sorry! An error has occurred, please report this to the website administrator.\n");
            } else {
                echo 
    '<div id="formfeedback"><h3>Thank You!</h3><p>'$thanksmessage .'</p></div>';
                unset(
    $_SESSION['myForm']);
                
    print_form();
                
            } 
    // end of if !mail
            
        
    } else { //report the errors
            
    echo '<div id="formfeedback"><h3>Error!</h3><p>The following error(s) has occurred:<br />';
            foreach (
    $errors as $msg) { //prints each error
                    
    echo " - $msg<br />\n";
                } 
    // end of foreach
            
    echo '</p><p>Please try again</p></div>';
            
    print_form();
        } 
    //end of if(empty($errors))

    // end of process_form()
    ?>

    the problem is thr $to is not working when i tried to equal to $emailfrom

  • #6
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    replace it:
    Code:
    $to = $emailfrom;
    with
    Code:
    $to = $_POST['emailfrom'];

  • Users who have thanked XterM for this post:

    scott_white85 (11-22-2011)

  • #7
    New Coder
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts
    still not receiving email...

  • #8
    New Coder
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts
    its already working i just add parenthesis $to = ($_POST['emailfrom']);.. thanks

  • #9
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts
    swoot


  •  

    Posting Permissions

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