表单提交PHP后重定向

时间:2014-04-14 19:12:19

标签: php jquery email

我想在用户输入电子邮件后重定向用户。我可以使用附件发送电子邮件,但无法将用户重定向到thankyou.html。如果我取消注释硬编码值并使用该重定向工作正常。不确定我做错了什么。任何帮助表示赞赏。

这是我的php文件:

<?php

//form variables
$to = $_POST['userEmail'];
$user_name = $_POST['userName'];
$subject = $_POST['subject'];
$fname = $_POST['filename'];
$mailcopyfile = $_POST['backupfile'];
//$subject = 'Templage from us';
//$fname = 'somefile.xlsx';
//$mailcopyfile = 'somefile.csv';

// common for all landing page emails
$from_name = 'MyCompany LLC';
$from_mail = 'admin@mycompany.com';
$now = date('Y-m-d H:i:s');
$num = md5(time());

$message  = "<html><body>";
$message .= "<span>Dear " . $user_name . ",</span>";
$message .= "<table><tr><td>Thank you for your interest in our company.</td></tr>";
$message .= "<tr><td>Here is the template you requested.</td></tr>";
$message .= "<tr><td>&nbsp;</td></tr>";
$message .= "<tr><td>Regards,</td></tr>";
$message .= "<tr><td>Our Team</td></tr>";
$message .= "</table>";
$message .= '<a href="http://www.mycompany.com"><img src="http://mycompany.com/Images/logo.jpg" alt="MyCompany LLC"></a>';
$message .= "</body></html>";

//File  open
$fp = fopen($fname, "rb");
$upload_size=filesize($fname);
$file = fread($fp, $upload_size);

$file = chunk_split(base64_encode($file));
fclose($fp);
$upload_type=filetype($fname);

//Normal headers

$headers   = "From: ".$from_name." <".$from_mail.">\r\n";
$headers  .= "Reply-To: ".$from_mail."\r\n";
$headers  .= "MIME-Version: 1.0\r\n";
$headers  .= "Content-Type: multipart/mixed; ";
$headers  .= "boundary=".$num."\r\n";
$headers  .= "--" .$num. "\r\n";

// With message

$headers .= "Content-Type: multipart/alternative; boundary=";
$headers .= $num. "\r\n";
$headers .= "--" .$num. "\r\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\r\nContent-Transfer-Encoding: 7bit\r\n";
$headers .= "Thanks for your interest in our company. Here is the template you requested. Thanks Our Team\r\n";
$headers .= "--" .$num. "\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= $message."\r\n\r\n";
$headers .= "--".$num."\r\n";

// Attachment headers

$headers  .= "Content-Type:".$upload_type."; ";
$headers  .= 'name="'.$fname.'"'. "\r\n";
$headers  .= "Content-Transfer-Encoding: base64\r\n";
$headers  .= "Content-Disposition: attachment; ";
$headers  .= 'filename="'.basename($fname).'"' . "\r\n";
$headers  .= $file."\r\n";
$headers  .= "--".$num."--";


//send the email
$mail_sent = @mail( $_POST['userEmail'], $subject, "", $headers );
//$mail_sent = @mail( 'myemail@hotmail.com', $subject, "", $headers );

if($mail_sent){
    $fp = fopen($mailcopyfile, "a");
    fputs($fp, $now . "\t" . $user_name . "\t" . $_POST['userEmail'] . "\t\n" );
    //fputs($fp, $now . "\t" . $user_name . "\t" . 'myemail@hotmail.com' . "\t\n" );
    fclose($fp);
    header('Location: Thankyou.html', true);
    exit;
}
?>

0 个答案:

没有答案