Skip to main content
Participant
April 23, 2018
Question

Text area in my php contact form won't work.

  • April 23, 2018
  • 1 reply
  • 429 views

Hello. I've been trying this for a while now, following a few different tutorials and and forum threads. It seems like a simple but i just cannot get the any data from textarea. Input type "name" & "mail" is Ok, it's working. I'll paste my php coding and my form below. Any help would be much appreciated. Thanks.

<section id="forma" >

    <div class="container">

      <div class="row">

        <div class="col-md-12 text-center">

          <form action="send.php" method="post" enctype="multipart/form-data" id="form_page">

            <input type="text" name="name" placeholder="Name" required>

            <input type="email" name="mail" placeholder="E-mail" required>

           <textarea name="comment" id="comment" style="margin: 0px 15px -33px 0px; width: 307px; height: 66px;"></textarea><br>

            <label class="uploadbutton">

            <div class="button" ></div>

            <div class='input'></div>

            <input type="file" name="file" onchange="this.previousSibling.previousSibling.innerHTML = this.value"/>

            </label>

            <button type="submit" class="btn btn2"></button>

          </form>

        </div>

      </div>

    </div>

  </section>

<?php

require_once('phpmailer/PHPMailerAutoload.php');

$mail = new PHPMailer;

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

$name = $_POST['name'];

$phone = $_POST['phone'];

$email = $_POST['mail'];

$text = $_POST['message'];

$comment = $_POST['comment'];

$mail->SMTPDebug = 3;                    

//$mail->isSMTP();                       

//$mail->Host = '';

//$mail->SMTPAuth = true;                          

//$mail->Username = '';

//$mail->Password = '';

//$mail->SMTPSecure = 'ssl';                       

//$mail->Port = 587;

$mail->setFrom('');

$mail->addAddress(''); 

//$mail->addAddress('');        

//$mail->addReplyTo('', 'Information');

//$mail->addCC('cc@example.com');

//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz');  

$mail->isHTML(true);

if(isset($_FILES['file']))

  $mail->addAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);    // Optional name$mail->isHTML(true);                           

$mail->Subject = '';

$mail->Body    = '' .$name . ' ,' .$comment. '<br>: ' .$email.'<br>' .$text;

$mail->AltBody = '';

if(!$mail->send()) {

    echo 'Error';

} else {

    header('location: thank-you.html');

}

?>

This topic has been closed for replies.

1 reply

Legend
April 23, 2018

https://forums.adobe.com/people/maryam+samee  wrote

Hello. I've been trying this for a while now, following a few different tutorials and and forum threads. It seems like a simple but i just cannot get the any data from textarea. Input type "name" & "mail" is Ok, it's working. I'll paste my php coding and my form below. Any help would be much appreciated. Thanks.

<section id="forma" >

    <div class="container">

      <div class="row">

        <div class="col-md-12 text-center">

          <form action="send.php" method="post" enctype="multipart/form-data" id="form_page">

            <input type="text" name="name" placeholder="Name" required>

            <input type="email" name="mail" placeholder="E-mail" required>

           <textarea name="comment" id="comment" style="margin: 0px 15px -33px 0px; width: 307px; height: 66px;"></textarea><br>

            <label class="uploadbutton">

            <div class="button" ></div>

            <div class='input'></div>

            <input type="file" name="file" onchange="this.previousSibling.previousSibling.innerHTML = this.value"/>

            </label>

            <button type="submit" class="btn btn2"></button>

          </form>

        </div>

      </div>

    </div>

  </section>

<?php

require_once('phpmailer/PHPMailerAutoload.php');

$mail = new PHPMailer;

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

$name = $_POST['name'];

$phone = $_POST['phone'];

$email = $_POST['mail'];

$text = $_POST['message'];

$comment = $_POST['comment'];

$mail->SMTPDebug = 3;                    

//$mail->isSMTP();                       

//$mail->Host = '';

//$mail->SMTPAuth = true;                          

//$mail->Username = '';

//$mail->Password = '';

//$mail->SMTPSecure = 'ssl';                       

//$mail->Port = 587;

$mail->setFrom('');

$mail->addAddress(''); 

//$mail->addAddress('');        

//$mail->addReplyTo('', 'Information');

//$mail->addCC('cc@example.com');

//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz');  

$mail->isHTML(true);

if(isset($_FILES['file']))

  $mail->addAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);    // Optional name$mail->isHTML(true);                           

$mail->Subject = '';

$mail->Body    = '' .$name . ' ,' .$comment. '<br>: ' .$email.'<br>' .$text;

$mail->AltBody = '';

if(!$mail->send()) {

    echo 'Error';

} else {

    header('location: thank-you.html');

}

?>

Are you getting anything from comment  if you alter the $mail->Body :

$mail->Body    = $comment;

or try:

$mail->Body    = $name . ' , ' . $comment . '<br>: ' . $email . '<br>' . $text;

Participant
April 23, 2018

@ $mail->Body    = $comment;  — i get nothing.

When  $mail->Body    = $name . ' , ' . $comment . '<br>: ' . $email . '<br>' . $text; —  only name and mail

Legend
April 23, 2018

Ok, probably wont work but try changing the name of the textarea to 'enquiry'

<textarea name="enquiry" id="comment" style="margin: 0px 15px -33px 0px; width: 307px; height: 66px;"></textarea><br>

and move the variable to the start:

$enquiry = $_POST['enquiry'];

$name = $_POST['name'];

$phone = $_POST['phone'];

$email = $_POST['mail'];

$text = $_POST['message'];

Replace 'comment' with 'enquiry':

$mail->Body    = $name . ' , ' . $enquiry . '<br>: ' . $email . '<br>' . $text;

Also if you are validating the form using javascript try commenting that out as the field may be being cleared. Infact try the form on a clean page without any js files attached at all.