Viewing file: save_request.php (6.3 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require("connection.php");
include 'functions.php';
include 'sendgrid_mail.php';
session_start();
date_default_timezone_set('Asia/Kolkata');
if ($_REQUEST["otp"]) {
$get_otp = $_REQUEST["otp"];
$user_id = $_SESSION['ur_id'];
$update = "update user_details set status='1',phone_verified='1' where otp='$get_otp' AND user_id='$user_id'";
$result1 = $con->query($update);
if ($result1) {
$get_details = "SELECT user_id, name, otp FROM user_details WHERE otp='" . $get_otp . "' AND user_id='$user_id'";
$get_details1 = mysqli_query($con, $get_details) or die("database error:" . mysqli_error($con));
$count_otp = $get_details1->num_rows;
if ($count_otp > 0) {
while ($row = $get_details1->fetch_assoc()) {
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['user_name'] = $row['name'];
echo 1;
}
}
} else {
echo 0;
}
} else {
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$course = $_POST["course"];
$type= $_POST["type"];
if($type=='demo')
{
$request_status=1;
$subject="New Demo Class Request";
}
else{
$request_status=2;
$subject="New Internship Request";
}
if(!isset($_SESSION['user_id']))
{
// generate OTP
$otp = rand(100000, 999999);
$check = "SELECT email, phone,status FROM user_details WHERE email='" . $email . "' or phone='".$phone."'";
$check = mysqli_query($con, $check) or die("database error:" . mysqli_error($con));
$count = $check->num_rows;
if ($count == 0) {
$query = "insert into user_details(`name`,`email`,`phone`,`otp`,`request_status`)
values('$name','$email','$phone','$otp','$request_status')";
$result = $con->query($query);
$count = $con->affected_rows;
if ($count > 0) {
$userid=$con->insert_id;
$messagephone='Dear '.$name.', You have successfully registered with Srishti Campus. Please use OTP '.$otp.' to login to your Srishti Campus account. This OTP can be used only once. Please DO NOT disclose it to anyone.';
send_otp_sms($phone,$messagephone,'signup');
$_SESSION['ur_id'] = $userid;
$sql1="INSERT into requests(user_id,course,request_type) VALUES ('$userid','$course','$request_status') ";
$result1=$con->query($sql1);
/*$to = 'srishticampusteam@srishtis.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Srishti <srishticampusteam@gmail.com>' . "\r\n".
'X-Mailer: PHP/' . phpversion();*/
$output = "<div style='font-size:15px;border-style: outset;'>"
. "<table style='margin-left:40px;'>"
. "<tr><td><caption><h4>".$subject."</h4></caption></td></tr>"
. "<tr><td>Name:</td><td>".$name." </td></tr>"
. "<tr><td>Phone:</td><td>".$phone."</td></tr>"
. "<tr><td>Email:</td><td>".$email."</td></tr>"
. "<tr><td>Course:</td><td>".$course."</td></tr></table></div></br>";
// create new sendgrid mail
$email = new \SendGrid\Mail\Mail();
// specify the email/name of where the email is coming from
$email->setFrom( FROM_EMAIL, FROM_NAME );
// set the email subject line
$email->setSubject( $subject );
// specify the email/name we are sending the email to
$email->addTo( TO_EMAIL, TO_NAME );
// add our email body content
$email->addContent("text/html", $output);
// create new sendgrid
$sendgrid = new \SendGrid( SENDGRID_API_KEY );
try {
// try and send the email
$response = $sendgrid->send( $email );
} catch ( Exception $e ) {
// something went wrong so display the error message
echo 'Caught exception: '. $e->getMessage() ."\n";
}
// mail($to,$subject,$output,$headers);
echo 1;
}
else {
echo 2;
}
} else {
echo 0;
}
}
else {
$userid=$_SESSION['user_id'];
$sql1="INSERT into requests(user_id,course,request_type) VALUES ('$userid','$course','$request_status') ";
$result1=$con->query($sql1);
/*$to = 'srishticampusteam@srishtis.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Srishti <srishticampusteam@gmail.com>' . "\r\n".
'X-Mailer: PHP/' . phpversion();*/
$output = "<div style='font-size:15px;border-style: outset;'>"
. "<table style='margin-left:40px;'>"
. "<tr><td><caption><h4>".$subject."</h4></caption></td></tr>"
. "<tr><td>Name:</td><td>".$name." </td></tr>"
. "<tr><td>Phone:</td><td>".$phone."</td></tr>"
. "<tr><td>Email:</td><td>".$email."</td></tr>"
. "<tr><td>Course:</td><td>".$course."</td></tr></table></div></br>";
// create new sendgrid mail
$email = new \SendGrid\Mail\Mail();
// specify the email/name of where the email is coming from
$email->setFrom( FROM_EMAIL, FROM_NAME );
// set the email subject line
$email->setSubject( $subject );
// specify the email/name we are sending the email to
$email->addTo( TO_EMAIL, TO_NAME );
// add our email body content
$email->addContent("text/html", $output);
// create new sendgrid
$sendgrid = new \SendGrid( SENDGRID_API_KEY );
try {
// try and send the email
$response = $sendgrid->send( $email );
} catch ( Exception $e ) {
// something went wrong so display the error message
echo 'Caught exception: '. $e->getMessage() ."\n";
}
//mail($to,$subject,$output,$headers);
echo 3;
}
}
?>
|