如何在发送电子邮件后使用数组更新php?

时间:2015-03-05 07:10:18

标签: php mysqli html-email

我有这个link,然后由此脚本处理:

<html>
<head>
</head>
<?php
/*//Disable error reporting
error_reporting(0);
*/
//Report runtime errors
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
//<script>location.replace("http://www.mntr.xxx.com/update.php");</script>

//Report all errors
error_reporting(E_ALL);
//end of error reporting
if(isset($_POST['submit']) && $_POST['submit'] == 'Send') {
//var_dump($_POST['users']);

$size= sizeof($_POST['users']);
$i = 0;

$message = NULL;

//    $message = null;
for($i=0; $i<$size; $i++){

$userId = $_REQUEST['users'][$i];
$message .= mailContent($userId);
   }

$to      = $_POST['email'];
$subject = 'This is a test';
$headers = 'From: xxx@live.com.ph' . "\r\n" .
'Reply-To: xxx@live.com.ph' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers  .= 'Content-Type: text/html; charset=ISO-8859-1\r\n';


mail($to, $subject, $message, $headers);
}

function mailContent($userId) {

$con=mysqli_connect("localhost","xxx","xxx","xxx");
$stmt = "SELECT * from CV where idvisa = '$userId'"; 
$result = mysqli_query($con, $stmt);
$row=mysqli_fetch_array($result);

$fName = $row['fName'];
$lName = $row['lName'];
$visaNumber = $row['visanumber'];
$idNumber = $row['idnumber'];
$statusApp = $row['statusapp'];
$accntVisaPhotoPath = $row['accntVisaPhotoPath'];
$passportPath = $row['passportPath'];

$message = "Your Username: YOUR EMAIL (small caps)     PASSWD: 1234
            <table>
            <tr>
            <td>Name</td><td>$fName $lName</td>
            </tr>
            <tr>
            <td>CVs</td><td><a href=\"http://public.xxx.com/biodataa.php?&idvisa=".$row['0']."&phoNamePath=".$row['30']."&position=".$row['28']."&emailApp=".$row['33']."&lName=".$row['34']."&fName=".$row['35']."&mName=".$row['36']."&pAdd=".$row['37']."&perAdd=".$row['38']."&age=".$row['39']."&bDate=".$row['40']."&pBirth=".$row['41']."&sex=".$row['42']."&languageSpoken=".$row['43']."&height=".$row['44']."&weight=".$row['45']."&bCivilStatus=".$row['46']."&bReligion=".$row['47']."&spouse=".$row['48']."&emergency=".$row['49']."&telemerCP=".$row['50']."&hs=".$row['51']."&hsComplete=".$row['52']."&hsGrad=".$row['53']."&hsDegree=".$row['54']."&coll=".$row['55']."&collComplete=".$row['56']."&collGrad=".$row['57']."&collDegree=".$row['58']."&voc=".$row['59']."&vocComplete=".$row['60']."&vocGrad=".$row['61']."&vocDegree=".$row['62']."&hc=".$row['63']."&hcComplete=".$row['64']."&hcGrad=".$row['65']."&hcDegree=".$row['66']."&local1_post=".$row['67']."&local1_fr=".$row['68']."&local1_to=".$row['69']."&local1_name=".$row['70']."&local1_add=".$row['71']."&local2_post=".$row['72']."&local2_fr=".$row['73']."&local2_to=".$row['74']."&local2_name=".$row['75']."&local2_add=".$row['76']."&local3_post=".$row['77']."&local3_fr=".$row['78']."&local3_to=".$row['79']."&local3_name=".$row['80']."&local3_add=".$row['81']."&local4_post=".$row['82']."&local4_fr=".$row['83']."&local4_to=".$row['84']."&local4_name=".$row['85']."&local4_add=".$row['86']."&local5_post=".$row['87']."&local5_fr=".$row['88']."&local5_to=".$row['89']."&local5_name=".$row['90']."&local5_add=".$row['91']." \" target=\"_blank\">Click Here</a></td>
            </tr>
            <tr>
            <td>Visa Number</td><td>$visaNumber</td>
            </tr>
            <tr>
            <td>ID Number</td><td>$idNumber</td>
            </tr>
            <tr>
            <td>Application Status</td><td>$statusApp</td>
            </tr>
            <tr>
            <td>Visa Copy</td><td><a href='http://mntr.xxx.com/".$accntVisaPhotoPath."'>Click to Download</a></td>
            </tr>
            <tr>
            <td>Passport Copy</td><td><a href='http://mntr.xxx.com/".$passportPath."'>Click to Download</a></td>
            </tr>   
            </table>";
  // OTHER LOGICS GO HERE

    return $message;

}

//Additional var
//Time
date_default_timezone_set('Asia/Manila');
//End Time  
$email = $_POST['email'];
$subdate = date("Y-m-d"); 
$subdate2 = date("Y-m-d");

if (empty($subdate)) {
$sql="UPDATE CV SET subdateEmail='$email',subdate='$subdate WHERE idvisa='$userId'";
} else {
$sql="UPDATE CV SET subdateEmail2='$email',subdate2='$subdate2' WHERE idvisa='$userId'";
}  
if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
} 
echo "<center>You have sent CV(s) </b><br/><br/><br/><br/>YOU MAY NOW    CLOSE THIS WINDOW</center>";
?>

它正在运行,但我希望更新所选用户中的4列(在本例中为idvisa)。现在,它没有更新。我正在考虑已被SELECTED的数组。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

使用此

error_reporting(E_ALL);
$con=mysqli_connect("localhost","xxx","xxx","xxx");


if(@mail($to, $subject, $message, $headers))
{
 ate_default_timezone_set('Asia/Manila');
//End Time  
$email = $_POST['email'];
$subdate = date("Y-m-d"); 
$subdate2 = date("Y-m-d");

if (empty($subdate)) {
$sql="UPDATE CV SET subdateEmail='$email',subdate='$subdate WHERE idvisa='$userId'";
} else {
$sql="UPDATE CV SET subdateEmail2='$email',subdate2='$subdate2' WHERE idvisa='$userId'";
}  
if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
} 
echo "<center>You have sent CV(s) </b><br/><br/><br/><br/>YOU MAY NOW    CLOSE THIS WINDOW</center>";
}else{
  echo "Mail Not Sent";
}