使用PHP通过电子邮件发送动态下载字段

时间:2019-02-18 21:26:32

标签: javascript php html mysql database

我创建了一个动态表单,用户可以在其中添加输入字段,然后将其发送到数据库,我也希望也通过电子邮件发送它,问题是当我收到电子邮件时,该字段上的内容为{ {1}}。

例如,电子邮件主题显示Array。插入数据库代码非常有效,只是我遇到问题的发送到电子邮件代码。

这是我的PHP代码:

PC Request for Array

这是我的index.php,以备不时之需:

<?php
//insert.php
$connect = mysqli_connect("localhost", "root", "", "pcrequesttest");
if(isset($_POST["reqname"]))
{
 $reqname = $_POST["reqname"];
 $date = $_POST["date"];
 $empname = $_POST["empname"];
 $position = $_POST["position"];
 $account = $_POST["account"];
 $platform = $_POST["platform"];
 $processor = $_POST["processor"];
 $ram = $_POST["ram"];
 $monitor = $_POST["monitor"];
 $phone = $_POST["phone"];
 $phonetype = $_POST["phonetype"];
 $headset = $_POST["headset"];
 $query = '';
 for($count = 0; $count<count($reqname); $count++)
 {
  $reqname_clean = mysqli_real_escape_string($connect, $reqname[$count]);
  $date_clean = mysqli_real_escape_string($connect, $date[$count]);
  $empname_clean = mysqli_real_escape_string($connect, $empname[$count]);
  $position_clean = mysqli_real_escape_string($connect, $position[$count]);
  $account_clean = mysqli_real_escape_string($connect, $account[$count]);
  $platform_clean = mysqli_real_escape_string($connect, $platform[$count]);
  $processor_clean = mysqli_real_escape_string($connect, $processor[$count]);
  $ram_clean = mysqli_real_escape_string($connect, $ram[$count]);
  $monitor_clean = mysqli_real_escape_string($connect, $monitor[$count]);
  $phone_clean = mysqli_real_escape_string($connect, $phone[$count]);
  $phonetype_clean = mysqli_real_escape_string($connect, $phonetype[$count]);
  $headset_clean = mysqli_real_escape_string($connect, $headset[$count]);
  if($reqname_clean != '' && $date_clean != '' && $empname_clean != '' && $position_clean != '' && $account_clean != '' && $platform_clean != '' && $processor_clean != '' && $ram_clean != '' && $monitor_clean != '' && $phone_clean != '' && $phonetype_clean != '' && $headset_clean != '')
  {
   $query .= '
   INSERT INTO item(reqname, date, empname, position, account, platform, processor, ram, monitor, phone, phonetype, headset) 
   VALUES("'.$reqname_clean.'", "'.$date_clean.'", "'.$empname_clean.'", "'.$position_clean.'", "'.$account_clean.'", "'.$platform_clean.'", "'.$processor_clean.'", "'.$ram_clean.'", "'.$monitor_clean.'", "'.$phone_clean.'", "'.$phonetype_clean.'", "'.$headset_clean.'"); 
   ';
  }
 }

 $email_from = "PC Request";//<== update the email address
$email_subject = "PC Request for $account";
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';

$message = '<html><body>';
$message .= "<tr><td>Good morning,</td></tr>";
$message .= "<br>";
$message .= "<br>";
$message .= "<tr><td>Here are the specifications:</td></tr>";
$message .= "<br>";
$message .= "<br>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="5">';
$message .= "<tr style='background: #CDD9FF;'><td><strong>Requested by</strong> </td><td>" . strip_tags($_POST['reqname']) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Start Date</strong> </td><td>" . strip_tags($_POST['date']) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>No. of Workstations</strong> </td><td>" . strip_tags($_POST['empname']) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Position</strong> </td><td>" . strip_tags($_POST['position']) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Account</strong> </td><td>" . strip_tags($_POST['account']) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Platform</strong> </td><td>" . strip_tags($_POST['platform']) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Processor</strong> </td><td>" . strip_tags($_POST['processor']) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>RAM</strong> </td><td>" . strip_tags($_POST['ram']) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Monitor</strong> </td><td>" . strip_tags($_POST['monitor']) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Phone</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Phone Type</strong> </td><td>" . strip_tags($_POST['phonetype']) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Headset</strong> </td><td>" . strip_tags($_POST['headset']) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>View Requests</strong> </td><td><a href='teamspan.com/core/pcrequest/messages-admin.php'>Click Here!</a></td></tr>";
$message .= "</table>";
$message .= "</body></html>";
    
$to = "email@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$message, $headers);
//done. redirect to thank-you page.
//header('Location: index.php');

 if($query != '')
 {
  if(mysqli_multi_query($connect, $query))
  {
   echo 'Successfuly Sent!';
  }
  else
  {
   echo 'Error';
  }
 }
 else
 {
  echo 'All fields are required!';
 }
}
?>

0 个答案:

没有答案