【发布时间】:2021-03-13 09:35:25
【问题描述】:
我编写了一个表单,我在其中使用 if 语句,因此当有人单击发送按钮时,此 if 语句将从“career-a.php”页面重定向到“thanks.php”页面。在thanks.php 页面中,我只是添加了带有感谢消息的引导列。但是这段代码并不指向其他页面。你能告诉我应该如何解决这个问题吗? 感谢.php之上的代码:
<?php
require "header.php";
session_start();
$message=$_SESSION['msg'];
echo $message;
?>
career-a.php 的代码(我在同一页面上添加了 php 和 html,因此提交按钮在同一页面上)。
<?php
$page = 'careers';
require "header.php";
?>
<?php
$statusMsg='';
if(isset($_FILES["file"]["name"])){
$email = $_POST['email'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$option = $_POST['option'];
$message = $_POST['message'];
if(!empty($_POST['check_list'])) {
$checks = array();
foreach($_POST['check_list'] as $check) {
$checks[] = $check;
}
$check = implode('</br>•', $checks);
}
$fromemail = $email;
$subject="Tell Us About Yourself to MyGeo";
$email_message = '<h2>User Information</h2>
<p><b>First Name:</b> '.$fname.'</p>
<p><b>Last Name:</b> '.$lname.'</p>
<p><b>Email:</b> '.$email.'</p>
<p><b>Phone:</b> '.$phone.'</p>
<p><b>Interest :</br></b> •'.$check .'</p>
<p><b>Field :</b> '.$option.'</p>
<p><b>Introduce Yourself :</b> '.$message.'</p>';
$email_message.="Please find the attachment";
$semi_rand = md5(uniqid(time()));
$headers = "From: ".$fromemail;
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
if($_FILES["file"]["name"]!= ""){
$strFilesName = $_FILES["file"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["file"]["tmp_name"])));
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: application/octet-stream;\n" .
" name=\"{$strFilesName}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$strContent .= "\n\n" .
"--{$mime_boundary}--\n";
}
$toemail="mail@mail.com";
if(mail($toemail, $subject, $email_message, $headers)){
session_start();
$_SESSION['msg'] = $statusMsg;
header("Location: thanks.php?mailsend");
}else{
}
}
?>
【问题讨论】:
-
我们需要查看更多代码,特别是导致
mail()的代码。我假设它失败了。 -
我已添加代码
-
去启用正确的 PHP 错误报告,我很确定这里会告诉你一些事情。
-
当我输入此代码时,它显示在顶部,但我想在其他页面上显示它:
if(mail($toemail, $subject, $email_message, $headers)){ $statusMsg= "Thank you for showing your interest"; }else{ $statusMsg= "Not sent"; } }