I'm having a little problem with my contact form. I'm using bootstrap and phpmailer. The problem is that the email body doesn't include variables from contact form.
The massage i'm getting on my email is "Wiadomość od: Firma: E-mail: Telefon: Treść wiadomości:
The code is down below:
<?php
require '../../PHPMailer-master/PHPMailerAutoload.php';
// require '../../PHPMailer-master/class.smtp.php';
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = false;
$mail->isSMTP();
$mail->Host = 'xxx.com.pl';
$mail->SMTPAuth = true;
$mail->Username = 'xxx@.com.pl';
$mail->Password = 'xxx';
$mail->Port = 587;
$mail->setFrom('xxx@.com.pl', 'Centru');
$mail->addAddress('xxx@gmail.com', 'Odbiorca');
$mail->Subject = "Wiadomość ze strony internetowej";
$mail->isHTML(true);
// $name = $_POST['InputName'];
// $company = $_POST['InputFirma'];
// $email = $_POST['InputEmail'];
// $phone = $_POST['InputPhone'];
// $message = $_POST['InputSubject'];
$mail->Body = "Wiadomość od: " .$_POST['InputName']."\nFirma: " .$_POST['InputFirma']. "\nE-mail: " .$_POST['InputEmail']. "\nTelefon: " .$phone = $_POST['InputPhone']. "\nTreść wiadomości: " .$_POST['InputSubject'];
if(!$mail->send()) {
echo 'Wiadomość nie mogła zostać wysłana';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Wiadomość została wysłana';
}
and HTML
<form class="padding-top-40" role="form" id="contactForm" class="contact-form" data-toggle="validator" class="shake">
<div class="form-group">
<label for="InputName">Imię i nazwisko</label>
<input type="text" class="form-control" id="InputName" name="fullname" placeholder="Imię i nazwisko" required data-error="Proszę wpisać swoje imię i nazwisko">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputFirma">Firma</label>
<input type="text" class="form-control" id="InputFirma" name="subject" name="comments" placeholder="Firma" required data-error="Proszę wpisać nazwę firmy">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputEmail">E-mail</label>
<input type="email" class="form-control" id="InputEmail" name="emailid" placeholder="E-mail" required data-error="Proszę wpisać swój email">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputPhone">Telefon kontaktowy</label>
<input type="number" class="form-control" name="phone" id="InputPhone" placeholder="Numer telefonu" required data-error="Proszę wprowadzić numer telefonu">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputSubject">Temat</label>
<textarea type="text" class="form-control" name="subject" id="InputSubject" placeholder="Treść wiadomości" rows="4" required data-error="Proszę wpisać treść wiadomości"></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="padding-top-20">
<button type="submit" value="send" class="btn btn-default" id="submit" >Wyślij</button>
<div id="msgSubmit" class="h3 text-center"></div>
</div>
</form>
thanks for help in advance!
Ok guys I've found a solution to my problem.
I've made an array instead of plain "body" script. Hope it will help someone.
$mail->Body = join('', array(
"Wiadomość od: ",
$_POST['name'],
"<br/>",
"Firma: ",
$_POST['company'],
"<br/>",
"E-mail: ",
$_POST['email'],
"<br/>",
"Telefon:",
$_POST['phone'],
"<br/>",
"Treść wiadomości: ",
"<br/>",
$_POST['content']
));