Visualizzazione risultati 1 fino 8 di 8

Discussione: form php invio email

  1. #1
    Guest

    Post form php invio email

    ragazzi quando un utente scrive i suoi dati mi arriva un email con i suoi dati, vorrei mettere l'ora di quando mi ha inviato l'email. grazie mille
    Codice PHP:
    codice php
    <?php

    //Includes user settings
    include('config.php');

    session_start();

    $name = $_POST['name'];
    $email = $_POST['email'];
    $tel = $_POST['tel'];
    $human = $_POST['humancheck'];
    $message = $_POST['message'];
    $callback = $_POST['callback'];
    $subject = $_POST['subject'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $error = false;

    //Reset error messages
    $_SESSION['emailerror'] = "";
    $_SESSION['nameerror'] = "";
    $_SESSION['subjecterror'] = "";
    $_SESSION['messageerror'] = "";
    $_SESSION['humanerror'] = "";
    $_SESSION['senderror'] = "";

    //Validation Session Variables
    $_SESSION['message'] = $message;
    $_SESSION['tel'] = $tel;
    $_SESSION['name'] = $name;
    $_SESSION['email'] = $email;
    $_SESSION['subject'] = $subject;

    //Validation

    if($name == ""){

    $_SESSION['nameerror'] = "Please type your name.";
    $error = true;

    }

    if(!
    eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {

    $_SESSION['emailerror'] = "Please check your email is valid.";
    $error = true;

    }

    if(
    $email == ""){

    $_SESSION['emailerror'] = "Please type in an email address.";
    $error = true;

    }

    if(
    $subject == ""){

    $_SESSION['subjecterror'] = "Please give a subject.";
    $error = true;

    }

    if(
    $message == ""){

    $_SESSION['messageerror'] = "Please type a message.";
    $error = true;

    }

    if(
    $human != "yes"){

    $error = true;
    $_SESSION['humanerror'] = "Please select yes.";

    }

    if(
    $error == true) {

    $_SESSION['senderror'] = "There are some incorrect or missing fields in the form!";
    header("Location: $contactpage");
    exit;

    } else {


    $to = $youremail;
    $sbj = "You have recieved a message - ContactKing";
    $msg = "
    <html>
    <head>
    <style type='text/css'>
    body{
    font-family:'Lucida Grande', Arial;
    color:#333;
    font-size:15px;
    }
    </style>
    </head>
    <body>
    <img src='"
    ."$logo"."' width='255' height='124' alt='contact' />
    <table width='600' border='0' cellspacing='0' cellpadding='5'>
    <tr>
    <td width='121' align='right' valign='baseline'><strong>Name:</strong></td>
    <td width='459'>
    $name</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Email:</strong></td>
    <td>
    $email</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>IP:</strong></td>
    <td>
    $ip</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Contact Number:</strong></td>
    <td>
    $tel</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Call back?:</strong></td>
    <td>
    $callback</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Subject:</strong></td>
    <td>
    $subject</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Message:</strong></td>
    <td>
    $message</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><small>Powered by ContactKing | &copy; Copyright 2010 creativeben.co.uk</small></td>
    </tr>

    </table>
    </body>
    </html>
    "
    ;

    $from = $email;
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "From: $from";


    mail($to,$sbj,$msg,$headers); //Send to you.

    //END OF EMAIL TO ME

    //START EMAIL CONFIRMATION

    $toClient = $email;
    $msgClient = "
    <html>
    <head>
    <style type='text/css'>
    body{
    font-family:'Lucida Grande', Arial;
    color:#333;
    font-size:15px;
    }
    </style>
    </head>
    <body>
    <img src='"
    ."$logo"."' width='255' height='124' alt='contact' />
    <table width='600' border='0' cellspacing='0' cellpadding='5'>
    <tr>
    <td width='117' align='right' valign='baseline'><strong>Thank you,</strong></td>
    <td width='463'>
    $name</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>We have recieved your message and will get back to you as soon as possible.</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><small>Powered by ContactKing | &copy; Copyright 2010 creativeben.co.uk</small></td>
    </tr>

    </table>
    </body>
    </html>
    "
    ;
    $fromClient = $email;
    $sbjClient = "Thank you, $name - $yourwebsite";
    $headersClient = 'MIME-Version: 1.0' . "\r\n";
    $headersClient .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headersClient .= "From: $fromClient";

    mail($toClient,$sbjClient,$msgClient,$headersClient); //Send to Client.

    //END EMAIL CONFIRMATION

    //Reset error messages
    $_SESSION['emailerror'] = "";
    $_SESSION['nameerror'] = "";
    $_SESSION['subjecterror'] = "";
    $_SESSION['messageerror'] = "";
    $_SESSION['humanerror'] = "";
    $_SESSION['senderror'] = "";

    //Reset Validation Session Variables
    $_SESSION['message'] = "";
    $_SESSION['tel'] = "";
    $_SESSION['name'] = "";
    $_SESSION['email'] = "";
    $_SESSION['subject'] = "";

    session_destroy();

    header("Location: $thankyoupage");
    exit;

    }

    ?>
    Ultima modifica di alemoppo : 17-03-2014 alle ore 21.16.48 Motivo: +tag [php]

  2. #2
    Guest

    Predefinito

    1) Metti il codice tra i tag [ php][/php], che altrimenti saresti fortunato a trovare qualcuno che si legga tutto il codice

    2) Per rivavare la data puoi usare la funzione date()...
    Per avere l'ora (ore:minuti) è:
    Codice PHP:
    date("H:i");

  3. #3
    Guest

    Predefinito

    non ho capito dove devo inserire date("H:i");

  4. #4
    Guest

    Predefinito

    Ad esempio, puoi modificare questo punto:
    Codice PHP:
    $msg = "
    <html>
    <head>
    <style type='text/css'>
    body{
    font-family:'Lucida Grande', Arial;
    color:#333;
    font-size:15px;
    }
    </style>
    </head>
    <body>
    <img src='"
    ."$logo"."' width='255' height='124' alt='contact' />
    <table width='600' border='0' cellspacing='0' cellpadding='5'>
    <tr>
    <td width='121' align='right' valign='baseline'><strong>Name:</strong></td>
    <td width='459'>
    $name</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Email:</strong></td>
    <td>
    $email</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>IP:</strong></td>
    <td>
    $ip</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Contact Number:</strong></td>
    <td>
    $tel</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Call back?:</strong></td>
    <td>
    $callback</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Subject:</strong></td>
    <td>
    $subject</td>
    </tr>
    <tr>
    <td align='right' valign='baseline'><strong>Message:</strong></td>
    <td>
    $message</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>Inviato alle "
    . date("H:i") . "</td> //(QUI HO MESSO LA DATA)
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><small>Powered by ContactKing | &copy; Copyright 2010 creativeben.co.uk</small></td>
    </tr>

    </table>
    </body>
    </html>
    "
    ;
    Ultima modifica di tampertools : 17-03-2014 alle ore 22.08.32

  5. #5
    Guest

    Predefinito

    okei modificato poi

  6. #6
    Guest

    Predefinito

    per mettere anche la data tipo 17/03/2014 come si può fare? comunque grazie mille per l'aiuto

  7. #7
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,683

  8. #8
    Guest

    Predefinito

    grazie mille

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •