电子邮件功能无效

时间:2014-11-26 17:24:59

标签: php sql-server pdo

由于某种原因,我无法收到电子邮件,因为它没有抓住用户lanId。不确定我做错了什么。我一直在试图找出lanID没有发布的原因,或者是否有另一种编写电子邮件功能的方法。

//update proccess 
<?php

$serverName = "localhost";
try{
$db= new PDO( "sqlsrv:server=$serverName ; Database=systems_requests", "test", "test");
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$sql = 'UPDATE requests Set name= :name, lanId= :lanId,  department= :department,manager= :manager,request= :request,request_comments= :request_comments,status= :status,comments= :comments,compUser= :compUser, compDt= :compDt WHERE id= :id';
$stmt = $db->prepare($sql);  
$stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);       
$stmt->bindParam(':lanId', $_POST['lanId'], PDO::PARAM_STR);       
$stmt->bindParam(':name', $_POST['name'], PDO::PARAM_STR); 
$stmt->bindParam(':department', $_POST['department'], PDO::PARAM_STR);   
$stmt->bindParam(':manager', $_POST['manager'], PDO::PARAM_STR);
$stmt->bindParam(':request', $_POST['request'], PDO::PARAM_STR);    
$stmt->bindParam(':request_comments', $_POST['request_comments'], PDO::PARAM_STR);
$stmt->bindParam(':status', $_POST['status'], PDO::PARAM_STR);
$stmt->bindParam(':comments', $_POST['comments'], PDO::PARAM_STR);
$stmt->bindParam(':compUser', $_POST['compUser'], PDO::PARAM_STR);
$stmt->bindParam(':compDt', $_POST['compDt'], PDO::PARAM_INT);
$stmt->execute();





$to = $_POST['lanId'] . "@exchange.test.com";
$subject = "Request";
$headers = "From: test@test.com";  

$message ="LanID: " . $_POST['lanId'] . " 


" ."User Name: ".  $_POST['name'] ." 

". "Department: " . $_POST['department'] . " 

" ."Manager: ".  $_POST['manager'] . " 

". "User Request: " . $_POST['request'] . "

" ."User Request comments: ".  $_POST['request_comments'].  "

" ."Status: " .  $_POST['status'] .  " 

" ."Systems comments: ".  $_POST['comments'] .  " 

" ."Completed by: ".  $_POST['compUser'] ;

mail($to,$subject,$message,$headers); 
}catch(PDOException $exception){ 
            echo "Error: " . $exception->getMessage();
    }   
?> 

update.php

 //start of form to select the id to update 
    <?php
        include('db_connect.php');
        $id=$_GET['id'];
        $result = $db->prepare("SELECT * FROM requests WHERE id= :id");
        $result->bindParam(':id', $id);
        $result->execute();
        for($i=0; $row = $result->fetch(); $i++){
    ?>

    <html>
    <head>
    <title></title>

    <style type="text/css">

    }
    .body{
        background-color: #F2F2F2;
        border: thin solid #666666;
    }
    </style>

    </head>
    <body class='body'>
    <form action = "update_process.php"  method ="post" class="Form">

    <p><input type ="hidden" name = "id" value="<?php print($id); ?>"</p>

    <h2 align="center">Users request  Information</h2>
    <table border='1' align="center">
    <tr>    
        <td>LAN ID:</td>
    <td><input type="text" value ="<?php  print($row['lanId']) ?>"name="lanId"></td>

        <td>Name:</td>
    <td><input type="text" value ="<?php  print($row['name']) ?>"name="name"></td>
    </tr>

    <tr>    
        <td>Department Location</td>
    <td><input type="text" value ="<?php  print($row['department']) ?>"name="department"></td>

        <td>Manager</td>
    <td><input type="text" value ="<?php  print($row['manager']) ?>"name="manager"></td>
    </tr>


    <tr>    
        <td>Request</td>
    <td><input type="text" value ="<?php  print($row['request']) ?>"name="request"></td>

    <td></td>
    <td></td>

    </tr>
    </table>
    <h2 align='center'>Requested Comments</h2>
    <table border='1' align="center">


    <tr>    

    <td width='400'  height="40">
    <textarea name="request_comments"  style="width: 600px; height: 81px" style="text-transform:uppercase ;"><?php echo $row['request_comments']; ?></textarea></td>

    </tr>

    </table>


    <h2 align="center">Complete or Update Requests Status</h2>

    <table border='1' align="center" style="width: 595px">
    <tr>    
        <td>Completed Date</td>
    <td style="width: 303px">
    <input type="text" value ="<?php echo date("m/d/Y",time())?>"name="compDt" style="width: 148px"></td>


    </tr>
    <tr>    
        <td>Status</td>
    <td style="width: 303px"><select name ="status" style="width: 149px" >
    <option value <?php if ($row['status']==1){ print('selected');}  ?> ="Received">Received</option>
    <option value <?php if ($row['status']==2){ print('selected');}  ?> ="Completed">Completed</option>
    <option value <?php if ($row['status']==3){ print('selected');}  ?> ="Cancelled">Cancelled</option>
    <option value <?php if ($row['status']==4){ print('selected');}  ?> ="In_Progress">In_Progress</option>
    <option value <?php if ($row['status']==5){ print('selected');}  ?> ="On_Hold">On_Hold</option>

    </select>
    </td>
    </tr>
    <tr>
        <td>Completed by</td>
    <td style="width: 303px"><select name ="compUser" style="width: 149px" >
    <option value <?php if ($row['compUser']==1){ print('selected');}  ?> ="">Please Select....</option>
    <option value <?php if ($row['compUser']==1){ print('selected');}  ?> ="xgrh">xgrh</option>
    <option value <?php if ($row['compUser']==2){ print('selected');}  ?> ="zeap">zeap</option>
    <option value <?php if ($row['compUser']==2){ print('selected');}  ?> ="xjae">xjae</option>
    <option value <?php if ($row['compUser']==5){ print('selected');}  ?> ="zmoj">zmoj</option>
    </select>
    </td>
    </tr>


    </table>
    <div align='center'>    
    <br>Systems Support Comments:<br>   
    <textarea name="comments" Value = "<?php  print($row['request_comments']) ?>"  style="width: 593px; height: 90px"></textarea><br>
        <br>

    <input type="submit" value= "Update Information">
    <br>
    </div>
    </form>


    </body>
    </html>
    <?php
        }
    ?>

1 个答案:

答案 0 :(得分:0)

我添加了一个变量并修剪它。现在它有效。我会对他们每个人都这样做。

 <?php

    $serverName = "localhost";
    try{
    $db= new PDO( "sqlsrv:server=$serverName ; Database=systems_requests", "test", "test");
    $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

  $lanId=trim($_POST['lanId']);

    $sql = 'UPDATE requests Set name= :name, lanId= :lanId,  department= :department,manager= :manager,request= :request,request_comments= :request_comments,status= :status,comments= :comments,compUser= :compUser, compDt= :compDt WHERE id= :id';
    $stmt = $db->prepare($sql);  
    $stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);       
   $stmt->bindParam(':lanId',  $lanId, PDO::PARAM_STR);     
    $stmt->bindParam(':name', $_POST['name'], PDO::PARAM_STR); 
    $stmt->bindParam(':department', $_POST['department'], PDO::PARAM_STR);   
    $stmt->bindParam(':manager', $_POST['manager'], PDO::PARAM_STR);
    $stmt->bindParam(':request', $_POST['request'], PDO::PARAM_STR);    
    $stmt->bindParam(':request_comments', $_POST['request_comments'], PDO::PARAM_STR);
    $stmt->bindParam(':status', $_POST['status'], PDO::PARAM_STR);
    $stmt->bindParam(':comments', $_POST['comments'], PDO::PARAM_STR);
    $stmt->bindParam(':compUser', $_POST['compUser'], PDO::PARAM_STR);
    $stmt->bindParam(':compDt', $_POST['compDt'], PDO::PARAM_INT);
    $stmt->execute();





  $to =   $lanId."@exchange.test.com";
    $subject = "Request";
    $headers = "From: test@test.com";  

$message ="LanID: "  .   $lanId . " 


    " ."User Name: ".  $_POST['name'] ." 

    ". "Department: " . $_POST['department'] . " 

    " ."Manager: ".  $_POST['manager'] . " 

    ". "User Request: " . $_POST['request'] . "

    " ."User Request comments: ".  $_POST['request_comments'].  "

    " ."Status: " .  $_POST['status'] .  " 

    " ."Systems comments: ".  $_POST['comments'] .  " 

    " ."Completed by: ".  $_POST['compUser'] ;

    mail($to,$subject,$message,$headers); 
    }catch(PDOException $exception){ 
                echo "Error: " . $exception->getMessage();
        }   
    ?>