-2

Hi i am getting this erorrs but i dont know where the problem is. I´ill be grateful for any advice.

Notice: Undefined variable: headers in C:\wamp\www\restaurace\kongresform.php on line 59

Notice: Undefined variable: messageb in C:\wamp\www\restaurace\kongresform.php on line 72

  if (empty($errors)) { //If everything is OK

        // send an email
        // Obtain file upload vars


        // Headers
         $headers.= "From: $emailfr \n";
         $headers.= "BCC: $emailcc ";

        // creates a boundary string. It must be unique
          $semi_rand = md5(time());
          $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

          // Add the headers for a file attachment
          $headers .= "\nMIME-Version: 1.0\n" .
                      "Content-Type: multipart/mixed;\n" .
                      "boundary=\"{$mime_boundary}\"";


          $messageb.="Dobrý den,<br>\n";

          $messageb.="Jméno a přijímení: <b>".$namefrom."</b><br>\n";
          $messageb.="Email: <b>".$email."</b><br>\n";

          $messageb.="Prostor pro poznámky: ".$message."<br><br>\n";
          $messageb.="S pozdravom<br>\n";
          $messageb.="tým Fincentrum Reality<br>\n";
          $messageb.="<br>\n";
          $messageb.="========================================================================<br>\n";
          $messageb.="Tento e-mail byl odeslaný automaticky z webu. Prosím, neodpovídejte na něj.<br>\n";
          $messageb.="========================================================================<br>\n"; 

         $subject="Potvrzení\n";





        // PHP Mailer
        $mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'mattoni.resta.test@gmail.com';                 // SMTP username
$mail->Password = 'mattonirestaurace';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom($emailfr);
$mail->addAddress($to);     // Add a recipient
//$mail->addReplyTo('webform@fincentrum.com', 'Information');
//$mail->addCC($emailcc);
$mail->addBCC($emailcc);

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $subject;
$mail->Body    = $messageb;
$mail->CharSet = 'UTF-8';
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';






        if(!$mail->send()) {
            exit("Mail could not be sent. Sorry! An error has occurred, please report this to the website administrator.\n");
            //echo 'Mailer Error: ' . $mail->ErrorInfo;
        } 
        else {
            echo '<div id="formfeedback"><h3>Děkujeme za Vaší zprávu!</h3><p>'. $thanksmessage .'</p></div>';
            unset($_SESSION['yellloForm']);
            print_form();

        } // end of if !mail

    }
george
  • 179
  • 2
  • 5
  • 16

2 Answers2

2

This:

$headers.= "From: $emailfr \n";

Is the same thing as this:

$headers = $headers . "From: $emailfr \n";

Which contains this:

$headers . "From: $emailfr \n";

But, at that time, $headers hasn't been defined. Hence the error, because you're trying to read from a variable that doesn't exist.

Just modify the first instance of the use of $headers to define it, rather than to try to use it:

$headers = "From: $emailfr \n";

Repeat for $messageb on the first line it's used as well.

David
  • 208,112
  • 36
  • 198
  • 279
  • 1
    *"Repeat for $messageb on the first line it's used as well."* - When they have to do the work themselves and to figure it out for themselves, is indeed the way to go and not spoonfeeding them ;-) good answer David. – Funk Forty Niner Jun 27 '16 at 13:41
-1

he's trying to append a value to a variable that has not been initialized.

change

$headers.= "From: $emailfr \n";

to

$headers = "From: $emailfr \n";

and

$messageb.="Dobrý den,<br>\n";

to

$messageb ="Dobrý den,<br>\n";
William L
  • 31
  • 6
  • 2
    so tell us, why should they do that? There's a reason you know; enlighten us. – Funk Forty Niner Jun 27 '16 at 13:44
  • he's trying to append a value to a variable that has not been initialized. – William L Jun 27 '16 at 13:49
  • Don't tell me that (I already know the "why"). What you said here in comments should have originally been part of your answer. Stack pro tip: When posting an answer (possible solution), is to "hit hard" right off the bat and will attract positive votes; that's if you're into those that is. – Funk Forty Niner Jun 27 '16 at 13:52