我对一个不会显示的结果有一个相当混乱的问题。我正在创建一个mailshot应用程序,并且我尝试使用收件人姓名和广告来填充电子邮件。当我将其存储为与其发送的电子邮件一起使用时,结果可以正常工作,但它不会显示在电子邮件正文中。它有点难以解释,但这是我正在使用的代码。我删除了很多电子邮件正文,因为它非常大,其中......就是我负载的地方。
<?php require (__DIR__.'/connections/connections.php');
session_start();
if(isset($_SESSION["UserID"])){
}else{
header('Location: login.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AzTecks Staff | Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/coin-slider.css" />
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</head>
<body>
<div class="main">
<div class="header">
<div class="header_resize">
<div class="menu_nav">
<ul>
<li><a href="index.php"><span>Staff Home</span></a></li>
<li><a href="Register_Client.php"><span>Register Client</span></a></li>
<li class="active"><a href="Register_Applicant.php"><span>Register Applicant</span></a></li>
<li><a href="Add_vacancy.php"><span>Add Vacancy</span></a></li>
<li><a href="logout.php"><span>Logout</span></a></li>
</ul>
</div>
<div class="logo">
<h1><a href="index.php"><span>AzTecks</span> <small style=" height: 12px; font-size: 11px;"> We Advise, We Avertise,</small><small style=" height: 12px; font-size: 11px;"> We Guarantee Not To Compromise</small></a></h1>
</div>
<div class="clr"></div>
<div class="slider">
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
</div>
<div class="content">
<div class="content_resize">
<div class="mainbar" style="margin-top:0px;">
<?php
echo "<div class=\"article\"><h2>Sending emails, please wait...</h2></div><br />";
/*Variables for mail shot query*/
$Keywords = $_SESSION['aKeywords'];
$Lname = $_SESSION['aLname'];
$Fname = $_SESSION['aFname'];
$CurrentJob = $_SESSION['aCurrentJob'];
$DesiredJob = $_SESSION['aDesiredJob'];
$CurrentSalary = $_SESSION['aCurrentSalary'];
$DesiredSalary = $_SESSION['aDesiredSalary'];
$Town = $_SESSION['aTown'];
$Country = $_SESSION['aCountry'];
$QualLevel = $_SESSION['aQualLevel'];
$Languages = $_SESSION['aLanguages'];
$TPC = $_SESSION['aTPC'];
$TechnicalTerms = $_SESSION['aTechnicalTerms'];
$ApplicantDivision = $_SESSION['aApplicantDivision'];
$query = "SELECT * FROM Applicants WHERE (? IS NULL OR CV_Text LIKE ?) AND (? IS NULL OR Applicant_Last_Name LIKE ?) AND (? IS NULL OR Applicant_First_Name LIKE ?) AND (? IS NULL OR Applicant_Current_Job_Title LIKE ?) AND (? IS NULL OR Applicant_Desired_Job_Title LIKE ?) AND (? IS NULL OR Applicant_Current_Salary >= ?) AND (? IS NULL OR Applicant_Desired_Salary >= ?) AND (? IS NULL OR Applicant_Town LIKE ?) AND (? IS NULL OR Applicant_Country LIKE ?) AND (? IS NULL OR Applicant_Qualification_Level LIKE ?) AND (? IS NULL OR Applicant_Languages LIKE ?) AND (? IS NULL OR T_P_C LIKE ?) AND (? IS NULL OR Applicant_Division LIKE ?) AND (? IS NULL OR Technical_Terms LIKE ?)";
$KeywordsW = '%'.$Keywords.'%';
$LnameW = '%'.$Lname.'%';
$FnameW = '%'.$Fname.'%';
$CurrentJobW = '%'.$CurrentJob.'%';
$DesiredJobW = '%'.$DesiredJob.'%';
$TownW = '%'.$Town.'%';
$CountryW = '%'.$Country.'%';
$QualLevelW = '%'.$QualLevel.'%';
$LanguagesW = '%'.$Languages.'%';
$TPCW = '%'.$TPC.'%';
$TechnicalTermsW = '%'.$TechnicalTerms.'%';
$ApplicantDivisionW = '%'.$ApplicantDivision.'%';
$stmt = $con->prepare($query);
$stmt->bind_param("ssssssssssiiiissssssssssssss", $Keywords, $KeywordsW, $Lname, $LnameW, $Fname, $FnameW, $CurrentJob, $CurrentJobW, $DesiredJob, $DesiredJobW, $CurrentSalary, $CurrentSalary, $DesiredSalary, $DesiredSalary, $Town, $TownW, $Country, $CountryW, $QualLevel, $QualLevelW, $Languages, $LanguagesW, $TPC, $TPCW, $ApplicantDivision, $ApplicantDivisionW, $TechnicalTerms, $TechnicalTermsW);
$stmt->execute() or die("Something went wrong, could not search :-(");
$result = $stmt->get_result();
$count = mysqli_num_rows($result);
if ($count == 0) {
$output = 'Sorry, no results found!';
echo $output;
}
else {
while($row = $result->fetch_object()) {
$id = $row->Applicant_ID;
$queryResult = $con->query("SELECT Contact_Email FROM Client_Contacts WHERE Contact_ID = {$_SESSION['coID']}");
$ContactDetails = $queryResult->fetch_object();
$email = $ContactDetails->Contact_Email;
$firstname = $row->Applicant_First_Name;
$lastname = $row->Applicant_Last_Name;
$mail_body = "<!doctype html>
<html>
...
Hello ".$ContactDetails->Contact_First_Name." ".$ContactDetails->Contact_Last_Name."<br /><br /><br />
Below is a potential applicant for your consideration.<br /><br />".$row->Applicant_Advert."<br /><br />
...</html>";
$subject = $_SESSION['eSubject'];
$headers = "From:natalie@aztecksonline.net\r\nContent-type: text/html\r\n";
$to = $email;
$mail_result = mail($to,$subject,$mail_body,$headers);
}
}
if($mail_result) {
echo "<script>window.alert(\"Mail Shot Sent!\");</script>";
header('location: index.php');
} else {
echo "Something went wrong :-(";
}
?>
</div>
<div class="sidebar">
<div class="searchform">
<form id="formsearch" name="formsearch" method="post" action="#">
<span>
<input name="editbox_search" class="editbox_search" id="editbox_search" maxlength="80" value="Search Applicants" type="text" />
</span>
<input name="button_search" src="images/search.gif" class="button_search" type="image" />
</form>
<br />
<div class="clr"><div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script>
</div>
</div>
<div class="clr"></div>
<div class="gadget">
<h2 class="star"><span>Sidebar</span> Menu</h2>
<div class="clr"></div>
<ul class="sb_menu">
<li><a href="index.php">Staff Home</a></li>
<li><a href="Register_Client.php">Register Client</a><a href="#"></a></li>
<li><a href="Register_Applicant.php">Register Applicant</a></li>
<li><a href="Add_Vacancy.php">Add Vacancy</a></li>
<li><a href="logout.php">Logout</a></li></ul>
</div>
<div class="gadget">
<h2 class="star"><span>Recent Vacancies</span></h2>
<div class="clr"></div>
<ul class="ex_menu">
<?php
if($cat_side_result = $con->query("SELECT Vacancy_ID, Vacancy_Job_Title, Vacancy_Location FROM Vacancies LIMIT 6")) {
if($cat_side_result->num_rows) {
while($cat_side_row = $cat_side_result->fetch_object()) {
echo '<li><a href="View_Vacancy_Category.php?id='.$cat_side_row->Vacancy_ID.'">'.$cat_side_row->Vacancy_Job_Title.'</a><br /> In '.$cat_side_row->Vacancy_Location.'</li>';
mysqli_close($con);
}
}
}
?>
</ul>
</div>
</div>
<div class="clr"></div>
</div>
</div>
<div class="fbg">
<div class="fbg_resize">
<div class="col c1">
<h2>Clients Recently Joined</h2>
<a href="#"><img src="images/Small_Company_logo_ABP.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/Jumpahead1.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/Keopple_logo_small.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/Phantom_small.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/graves-capital_small.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/global-financial-logo_small.gif" width="75" height="75" alt="" class="gal" /></a> </div>
<div class="col c2">
<h2><span>Services</span> Overview</h2>
<p>At AzTecks we are committed to insuring you have total confidentiality, and do not share any data or information without your say so, please read our privacy agreement for more information.</p>
<ul class="fbg_ul">
<li><a href="about.php">More about us</a></li>
<li><a href="Register-Coming_Soon.php">Privacy agreement</a></li>
<li><a href="contact.php">Contact us</a></li>
</ul>
</div>
<div class="col c3">
<h2><span>Contact</span> Us</h2>
<p>If you have any querys about us or have any questions please feel free to contact us.</p>
<p class="contact_info"> <span>Address:</span>1 Shaw Street<br />
Worcester , Worcestershire , UK<br />
<span>Postcode:</span> WR1 3QQ<br />
<span>Telephone:</span> 01905 700158<br />
<span>E-mail:</span><a href="#">info@aztecksonline.net</a></p>
</div>
<div class="clr"></div>
</div>
</div>
<div class="footer">
<div class="footer_resize">
<p class="lf">© Copyright <a href="index.php">AzTecks</a>.</p>
<div style="clear:both;"></div>
</div>
</div>
</div>
</body>
</html>
&#13;
$ email填充正常,因为它发送的电子邮件没有任何问题,但它在电子邮件正文$ContactDetails->Contact_First_Name
中显示的位置,它根本不显示。
我做了一些相当愚蠢的事情还是有别的错误?
答案 0 :(得分:0)
查询应如下所示:
SELECT Contact_Email, Contact_First_Name, Contact_Last_Name FROM Client_Contacts WHERE Contact_ID = {$_SESSION['coID']}
您忘记将Contact_First_Name
和Contact_Last_Name
添加到其中,因此甚至无法获取它们。
答案 1 :(得分:-1)
首先在顶部添加。
error_reporting(E_ALL);
ini_set('display_errors', '1');
然后添加一个die();或退出();在实际执行任何数据库更新之前,然后检查php显示的错误中的错误。
通常这是因为执行有问题的SQL的非法方式。尝试一下。
答案 2 :(得分:-2)
首先,你应该写一个可读的代码。
现在这是一个非常糟糕的意大利面条代码,带有疯狂的缩进(阅读PSR)。
之后,将PHP与HTML分开,并将与数据库的交互移动到不同的层。