Autor Zpráva
Jana Novotná
Profil
Ahoj koupila jsem si šablonu kde byl základní jednoduchý formulář tedy Jméno email telefon a předmět. Funguje v pohodě já jsem si chtěla přidat ještě nějaká políčka a tak jsem si přidala telefon, kód níže:
<div class="container">

                    <div class="row mt-xl">
                        <div class="col-md-10 col-md-offset-1">

                            <div class="alert alert-success hidden mt-lg" id="contactSuccess">
                                <strong>Juchůůů!</strong> Vaše zpráva byla odeslána.
                            </div>

                            <div class="alert alert-danger hidden mt-lg" id="contactError">
                                <strong>Ajaj!</strong> Někde se stala chybička.
                                <span class="font-size-xs mt-sm display-block" id="mailErrorMessage"></span>
                            </div>

                            <form id="contactForm" action="php/contact-form.php" method="POST">
                                <div class="row">
                                    <div class="form-group">
                                        <div class="col-md-12">
                                            <input type="text" placeholder="Vaše jméno a příjmení" value="" data-msg-required="Zadejte své jméno a příjmení." maxlength="100" class="form-control input-lg" name="name" id="name" required>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group">
                                        <div class="col-md-12">
                                            <input type="email" placeholder="Váš E-mail" value="" data-msg-required="Zadejte Vaši emailovou addresu." data-msg-email="Please enter a valid email address." maxlength="100" class="form-control input-lg" name="email" id="email" required>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group">
                                        <div class="col-md-12">
                                            <input type="text" placeholder="Váš Telefon" value="" data-msg-required="Zadejte Váš telefon."  maxlength="9" class="form-control input-lg" name="phone" id="phone" required>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group">
                                        <div class="col-md-12">
                                            <input type="text" placeholder="Předmět" value="" data-msg-required="Zadejte předmět." maxlength="100" class="form-control input-lg" name="subject" id="subject" required>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group">
                                        <div class="col-md-12">
                                            <textarea maxlength="5000" placeholder="Zpráva" data-msg-required="Zda napište Váš dotaz." rows="10" class="form-control input-lg" name="message" id="message" required></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <input type="submit" value="Odeslat zprávu" class="btn btn-primary btn-lg mb-xs" data-loading-text="Loading...">
                                    </div>
                                </div>
                            </form>
                        </div>

                    </div>

                </div>
Jenže políčko telefon se neodešle, respektive odešle, ale zůstane prázdné. Formulář zpracovává tento skript:
<?php


session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));

header('Content-type: application/json');

require_once('php-mailer/PHPMailerAutoload.php');

// Step 1 - Enter your email address below.
$email = 'janule***@seznam.cz';

// If the e-mail is not working, change the debug option to 2 | $debug = 2;
$debug = 0;

$subject = $_POST['subject'];

$fields = array(
    0 => array(
        'text' => 'Name',
        'val' => $_POST['name']
    ),
    1 => array(
        'text' => 'Email address',
        'val' => $_POST['email']
    ),
    2 => array(
        'text' => 'Phone',
        'val' => $_POST['phone']
    ),
    3 => array(
        'text' => 'Message',
        'val' => $_POST['message']
    )
);

$message = '';

foreach($fields as $field) {
    $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}

$mail = new PHPMailer(true);

try {

    $mail->SMTPDebug = $debug;                                 // Debug Mode

    // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:

    //$mail->IsSMTP();                                         // Set mailer to use SMTP
    //$mail->Host = 'mail.yourserver.com';                       // Specify main and backup server
    //$mail->SMTPAuth = true;                                  // Enable SMTP authentication
    //$mail->Username = 'user@example.com';                    // SMTP username
    //$mail->Password = 'secret';                              // SMTP password
    //$mail->SMTPSecure = 'tls';                               // Enable encryption, 'ssl' also accepted
    //$mail->Port = 587;                                          // TCP port to connect to

    $mail->AddAddress($email);                                    // Add another recipient

    //$mail->AddAddress('person2@domain.com', 'Person 2');     // Add a secondary recipient
    //$mail->AddCC('person3@domain.com', 'Person 3');          // Add a "Cc" address. 
    //$mail->AddBCC('person4@domain.com', 'Person 4');         // Add a "Bcc" address. 

    $mail->SetFrom($email, $_POST['name']);
    $mail->AddReplyTo($_POST['email'], $_POST['name']);

    $mail->IsHTML(true);                                  // Set email format to HTML

    $mail->CharSet = 'UTF-8';

    $mail->Subject = $subject;
    $mail->Body    = $message ;

    $mail->Send();
    $arrResult = array ('response'=>'success');

} catch (phpmailerException $e) {
    $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
} catch (Exception $e) {
    $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
}

if ($debug == 0) {
    echo json_encode($arrResult);
}
Hando
Profil
Ahoj.

Co jsem zkoušel, tak políčko "phone" se normálně odešle, takže tam by problém být neměl... Další políčka "navíc" jsem v kódu neviděl...

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0