Pravissimo Pravissimo - 1 year ago 70
PHP Question

Phpmailer - add posted value in email body

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:


require '../../PHPMailer-master/PHPMailerAutoload.php';
// require '../../PHPMailer-master/class.smtp.php';

$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = false;
$mail->Host = '';
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = 'xxx';
$mail->Port = 587;

$mail->setFrom('', 'Centru');
$mail->addAddress('', 'Odbiorca');
$mail->Subject = "Wiadomość ze strony internetowej";

// $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 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 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 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 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 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>

thanks for help in advance!

Answer Source

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: ",
"Firma: ",
"E-mail: ",
"Treść wiadomości: ",
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download