The problem is that when I try to send the contents of the HTML form with PHPMailer it does not grab the data from the form.
Tried with many possible solutions but none of them worked, and I think my formatting is correctly done, so I just kinda lost hope…
There is also a similar question marked solved but I watched that and there were only formatting problems, and the rest of the code looks real similar to mine.
The following is the PHP code I used for the email sending:
<?php
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
use PHPMailerPHPMailerException;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
if(isset($_POST['submit'])){
try {
$nev = $_POST['nev'];
$email = $_POST['email'];
$telefon = $_POST['telefon'];
$allat = $_POST['allat'];
$felnott = $_POST['felnott'];
$gyerekek = $_POST['gyerekek'];
$erkezes = $_POST['erkezes'];
$tavozas = $_POST['tavozas'];
$szamlanev = $_POST['szamlanev'];
$szamlacim = $_POST['szamlacim'];
$fizetesmod = $_POST['fizetesmod'];
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->Host = ''; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = ''; //SMTP username
$mail->Password = ''; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('');
$mail->addAddress('');
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Uj foglalas';
//$mail->Body = "Név: " . $nev . "nEmail: ". $email . "nTelefon: " . $telefon . "nÁllat: " . $allat . "nFelnőttek szama: " . $felnott . "nGyerekek szama: " . $gyerekek . "nErkezes: " . $erkezes . " Tavozas: " . $tavozas . "nSzámlaNév: " . $szamlanev . "nSzámlaCím: " . $szamlacim . "nFizetésimód: " . $fizetesmod;
//$mail->Body = $_POST['nev'].$_POST['email'].$_POST['telefon'];
$mail->Body = '<html><body>
<p>Someone has submitted your form.</p>
<table rules="all" style="border-color: #666;" cellpadding="10">
<tr style="background: #eee;"><td><strong>Sent From:</strong> </td><td>The Web Form</td></tr>
<tr><td><strong>Name:</strong> </td><td>' .$_POST['nev']. '</td></tr>
<tr><td><strong>Email:</strong> </td><td>' .$_POST['email']. '</td></tr>
<tr><td><strong>Phone:</strong> </td><td>' .$telefon. '</td></tr>
<tr><td><strong>Comments:</strong> </td><td>' .$fizetesmod. '</td></tr>
</table>
</body></html>';
$mail->send();
header('Location: foglalt.html');
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>
This is the HTML code I was trying with:
<h3 class="w3-center"><u>FOGLALÁS</u></h3>
<br>
<div class="w3-container w3-white w3-padding-16">
<form action="send_PHPMailer.php" method="POST">
<div class="w3-row-padding" style="margin:0 -16px;">
<div class="w3-half w3-margin-bottom">
<label><i class="fa fa-address-card"></i> Név</label>
<input class="w3-input w3-border" type="text" name="Név" id="nev" required placeholder="Vendégház Vanda">
</div>
<div class="w3-half">
<label><i class="fa fa-envelope"></i> E-mail</label>
<input class="w3-input w3-border" type="email" name="Email" id="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$" required placeholder="[email protected]">
</div>
</div>
<div class="w3-row-padding" style="margin:0 -16px;">
<div class="w3-half w3-margin-bottom">
<label><i class="fa fa-phone"></i> Telefon</label>
<input class="w3-input w3-border" type="text" name="Telefon" id="telefon" required placeholder="06338893745">
</div>
<div class="w3-half">
<label><i class="fa fa-paw"></i> Kisállat</label>
<select class="w3-input w3-border" style="height: 45px;" id="allat" name="Állat">
<option value="igen">Igen</option>
<option value="nem">Nem</option>
</select>
</div>
</div>
<div class="w3-row-padding" style="margin:8px -16px;">
<div class="w3-half w3-margin-bottom">
<label><i class="fa fa-male"></i> Felnőttek</label>
<input class="w3-input w3-border" type="number" value="1" name="Felnőttek" id="felnott" min="1" max="6">
</div>
<div class="w3-half">
<label><i class="fa fa-child"></i> Gyerekek</label>
<input class="w3-input w3-border" type="number" value="0" name="Gyerekek" id="gyerekek" min="0" max="6">
</div>
</div>
<div class="w3-row-padding" style="margin:0 -16px;">
<div class="w3-half w3-margin-bottom">
<label><i class="fa fa-calendar"></i> Érkezés</label>
<input type="date" class="w3-input w3-border" type="text" name="Érkezés" id="erkezes" required>
</div>
<div class="w3-half">
<label><i class="fa fa-calendar"></i> Távozás</label>
<input type="date" class="w3-input w3-border" type="text" name="Távozás" id="tavozas" required>
</div>
</div>
<div class="w3-row-padding" style="margin:0 -16px;">
<div class="w3-half w3-margin-bottom">
<label><i class="fa fa-address-card"></i> Számlázási Név</label>
<input class="w3-input w3-border" type="text" name="SzámlaNév" id="szamlanev" required placeholder="Vendégház Vanda">
</div>
<div class="w3-half">
<label><i class="fa fa-map"></i> Számlázási Cím</label>
<input class="w3-input w3-border" type="text" name="SzámlaCím" id="szamlacim" required placeholder="2030, Város, Utcák utcája 21/b">
</div>
</div>
<div class="w3-center">
<label><i class="fa fa-credit-card"></i> Fizetési mód</label>
<select class="w3-input w3-border w3-center" style="height: 45px;" id="fizetesmod" name="Fizetésimód">
<option value="Készpénz">Készpénz</option>
<option value="Átutalás">Banki átutalás</option>
<option value="Otpszép">OTP SZÉP kártya</option>
</select>
</div>
<br>
<div class="w3-center">
<button class="w3-button w3-dark-grey" type="submit" name="submit"><i class="fa fa-paper-plane w3-margin-right"></i>Foglalás</button>
</div>
</form>```
Tried many ways to get it through but none of them works, the Email is sent just fine but the variables are not in there.
[enter image description here](https://i.sstatic.net/es1LWUvI.png)
Mrton Mszros Jazzay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.