Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'database/connect.php';
- global $connect;
- date_default_timezone_set('Etc/UTC');
- require 'PHPMailer-master2/PHPMailerAutoload.php';
- if ( isset($_POST['data1']) && isset($_POST['data2']))
- {
- $data1 = $_POST['data1'];
- $data2 = $_POST['data2'];
- $sql = "SELECT * FROM table WHERE data1 = '$data1' AND data2='$data2'";
- $result = mysqli_query($connect, $sql);
- if ($result && mysqli_num_rows($result) > 0)
- {
- while ($row = mysqli_fetch_array($result)){
- }
- $output = array('message' => '1');
- echo json_encode($output);
- $add = "INSERT INTO table (data1, data2)
- VALUES ('$data1','$data2')
- ";
- $run = mysqli_query($connect,$add);
- $mail = new PHPMailer;
- $mail->isSMTP();
- $mail->Host = 'smtp.gmail.com';
- $mail->SMTPAuth = true;
- $mail->Username = 'gmail.com';
- $mail->Password = '******';
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
- $mail->setFrom('sender@mail.com', 'sender');
- $mail->addAddress('receiver@mail.com','receiver');
- $mail->isHTML(true);
- $mail->Subject = 'Test';
- $mail->Body = 'Test';
- $mail->AltBody = 'Test';
- if(!$mail->send()) {
- echo json_encode([
- 'status' => false,
- 'message' => 'Message could not be sent. Error: ' . $mail->ErrorInfo
- ]);
- } else {
- $status = array();
- $status[] = array('status' => '1');
- }
- $output = array('message' => '1', 'status' => $status);
- echo json_encode($output);
- exit();
- // End sending email
- exit();
- mysqli_free_result($result);
- }
- else {}
- }
- ?>
- @IBAction func sendApplyMovement(_ sender: Any) {
- let url = URL(string: "http://localhost/send.php")
- let session = URLSession.shared
- let request = NSMutableURLRequest(url: url! as URL)
- request.httpMethod = "POST"
- let valueToSend = "data1=&data2"
- request.httpBody = valueToSend.data(using: String.Encoding.utf8)
- let myAlert = UIAlertController(title: "Confirm", message: "Sure ?", preferredStyle: UIAlertControllerStyle.alert)
- let cancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler: nil)
- let okaction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.default, handler:
- {
- action in
- let task = session.dataTask(with: request as URLRequest, completionHandler: {
- (data, response, error) in
- if error != nil {
- return
- }
- else {
- do {
- if let json = try JSONSerialization.jsonObject(with: data!) as? [String: String]
- {
- DispatchQueue.main.async {
- let message = Int(json["message"]!)
- let status = Int(json["status"]!)
- if(message == 1){
- if(status == 1){
- print("Success")
- let myViewController:ViewController = self.storyboard!.instantiateViewController(withIdentifier: "ViewController") as! ViewController
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- let navigationController = UINavigationController.init(rootViewController: myViewController)
- appDelegate.window?.rootViewController = navigationController
- appDelegate.window?.makeKeyAndVisible()
- let myAlert = UIAlertController(title: "Success!", message: "Sent !", preferredStyle: UIAlertControllerStyle.alert)
- myAlert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil))
- navigationController.present(myAlert, animated: true, completion: nil)
- return
- }
- }
- else {return}
- }
- }
- }
- catch let parseError { print("Parse error: (parseError.localizedDescription)") }
- }
- })
- task.resume()
- }
- )
- myAlert.addAction(okaction)
- myAlert.addAction(cancel)
- self.present(myAlert, animated: true, completion: nil)
- }
- }
- if let json = try JSONSerialization.jsonObject(with: data!)
- if(!$mail->send())
- {
- echo 'Message could not be sent.';
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- }
- else
- {
- echo 'Message has been sent';
- }
- if(!$mail->send()) {
- echo json_encode([
- 'status' => false,
- 'message' => 'Message could not be sent. Error: ' . $mail->ErrorInfo
- ]);
- } else {
- echo json_encode([
- 'status' => true,
- 'message' => 'Message sent'
- ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement