phpmailer未定义变量

时间:2016-06-27 13:37:25

标签: php phpmailer

您好我得到了这个错误,但我不知道问题出在哪里。 我很感激任何建议。

注意:未定义的变量:第59行的C:\ wamp \ www \ restaurace \ kongresform.php中的标题

注意:未定义的变量:第72行的C:\ wamp \ www \ restaurace \ kongresform.php中的messageb

  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

    }

2 个答案:

答案 0 :(得分:2)

此:

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

与此相同:

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

其中包含:

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

但是,当时$headers尚未定义。因此错误,因为你试图从一个不存在的变量中读取。

只需修改使用$headers的第一个实例来定义它,而不是尝试使用它:

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

在它使用的第一行重复$messageb

答案 1 :(得分:-1)

他试图将值附加到尚未初始化的变量。

变化

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

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

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

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