Witam
Potrzebuje formularza kontaktowego na stronie gdzie będzie możliwość przesyłania wiadomości + plik PDF
Mam taki kod:
HTML
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_name">Imię</label>
<input id="form_name" type="text" name="name" class="form-control" placeholder="Proszę podać imię *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_lastname">Nazwisko</label>
<input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Proszę podać nazwisko *" required="required" data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_email">Email *</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Proszę podać email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_message">Numer oferty</label>
<input id="form_message" type="text" name="message1" class="form-control" placeholder="Proszę podać numer oferty *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_phone">Telefon</label>
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Proszę podać telefon">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_file">CV</label>
<input id="form_file" type="file" name="phone" class="form-control" placeholder="Proszę podać telefon">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="form_message">Wiadomość</label>
<textarea id="form_message" name="message" class="form-control" placeholder="Wpisz tekst wiadomości *" rows="4" required="required" data-error="Please,leave us a message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-send" value="Wyślij wiadomość">
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="text-muted"><strong>*</strong> Pola wymagane</p>
</div>
</div>
</div>
</form>
Mam taki kod PHP
<?php
/*
* CONFIGURE EVERYTHING HERE
*/
// an email address that will be in the From field of the email.
$from = 'demo <[email protected]>';
// an email address that will receive the email with the output of the form
$sendTo = 'demo <[email protected]>';
// subject of the email
$subject = 'Zgloszenie kandydatury';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Imię', 'surname' => 'Nazwisko', 'phone' => 'Telefon', 'email' => 'Email', 'message' => 'Wiadomość', 'message1' => 'Numer oferty');
// message that will be displayed when everything is OK :)
$okMessage = 'Dziękujemy za zgłoszenie kandydatury';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
/*
* LET'S DO THE SENDING
*/
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailText = "Zgłoszono kandydaturę\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
// if requested by AJAX request return JSON response
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
// else just display the message
else {
echo $responseArray['message'];
}
I teraz pytanie jak połączyć tego HTML poniżej z plikiem PHP żeby ten plik rzeczywiście dodawał się do wiadomości?
<div class="form-group">
<label for="form_file">CV</label>
<input id="form_file" type="file" name="phone" class="form-control" placeholder="CV">
<div class="help-block with-errors"></div>
</div>
</div>