简体   繁体   English

标头重定向不起作用

[英]Header redirect doesn't work

I am using PHPmailer for sending a mail. 我正在使用PHPmailer发送邮件。 I use the same script on each website. 我在每个网站上使用相同的脚本。 But suddenly, header redirect doesn't work and I really have no idea why... 但是突然之间,标头重定向不起作用,我真的不知道为什么...

Cut of the code is below, I appreciate every advice, thanks! 截断的代码如下,我感谢每一个建议,谢谢!

EDIT: FULL CODE ADDED 编辑:添加完整代码

<?php
require_once("phpmailer/class.phpmailer.php");

if (isset($_POST['odeslat'])){
  $allowedExts = array("doc", "docx", "xls", "xlsx", "pdf");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);

$jmeno = $_POST['jmeno'];
$email = $_POST['email'];
$telefon = $_POST['telefon'];
$text = $_POST['zprava'];

$mail = new PHPMailer();


//From email address and name
$mail->CharSet = "UTF-8";
$mail->From = "info@mail.com";
$mail->FromName = "MAIL";

//To address and name

$mail->addAddress("yourmail@mail.com"); //Recipient name is optional
$mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Server email";
$mail->Body = "<p><strong>Jméno:</strong> $jmeno</p>
<p><strong>E-mail:</strong> $email</p>
<p><strong>Telefon:</strong> $telefon</p>
<p><strong>Text:</strong> $text</p>
";
$mail->AltBody = "Jméno: $jmeno \n
E-mail: $email \n
Telefon: $telefon \n
Text: $text\n
";

if(!$mail->send()) 
{
   header ("Location: http://mypage.com/dotaznik.php?e=1");
   exit();
} 
else 
{
header ("Location: http://mypage.com/dotaznik.php?o=1");
exit();
}
}
?>

Just Use this code: 只需使用以下代码:

 <?php
 require_once("phpmailer/class.phpmailer.php");

 if (isset($_POST['odeslat'])){
 $allowedExts = array("doc", "docx", "xls", "xlsx", "pdf");
 $temp = explode(".", $_FILES["file"]["name"]);
 $extension = end($temp);

$jmeno = $_POST['jmeno'];
$email = $_POST['email'];
$telefon = $_POST['telefon'];
$text = $_POST['zprava'];

$mail = new PHPMailer();


 //From email address and name
 $mail->CharSet = "UTF-8";
 $mail->From = "info@mail.com";
 $mail->FromName = "MAIL";

 //To address and name

 $mail->addAddress("yourmail@mail.com"); //Recipient name is optional
 $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);

 //Send HTML or Plain Text email
 $mail->isHTML(true);

 $mail->Subject = "Server email";
 $mail->Body = "<p><strong>Jméno:</strong> $jmeno</p>
 <p><strong>E-mail:</strong> $email</p>
 <p><strong>Telefon:</strong> $telefon</p>
 <p><strong>Text:</strong> $text</p>
 ";
 $mail->AltBody = "Jméno: $jmeno \n
 E-mail: $email \n
 Telefon: $telefon \n
 Text: $text\n
 ";

 if(!$mail->send()) 
 {
  echo '<script type="text/javascript">';  
  echo 'window.location.href = "http://mypage.com/dotaznik.php?e=1"';
  echo '</script>';

 } 
 else 
 {
  echo '<script type="text/javascript">';  
  echo 'window.location.href = "http://mypage.com/dotaznik.php?o=1"';
  echo '</script>';
 }
 }
 ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM