Reputation: 301
I am using PHPmailer for sending a mail. 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 = "[email protected]";
$mail->FromName = "MAIL";
//To address and name
$mail->addAddress("[email protected]"); //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();
}
}
?>
Upvotes: 0
Views: 119
Reputation: 203
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 = "[email protected]";
$mail->FromName = "MAIL";
//To address and name
$mail->addAddress("[email protected]"); //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>';
}
}
?>
Upvotes: 1