• Exclusive

    Hey Guest, unlock an instant 10% bonus discount when you upgrade via the Crypoverse gateway.

PHP Function for Sending HTTP Post Request and Extracting Emails (1 Viewer)

Currently reading:
 PHP Function for Sending HTTP Post Request and Extracting Emails (1 Viewer)

Recently searched:

james125

Member
LV
3
Joined
Nov 30, 2022
Threads
19
Likes
49
Awards
7
Credits
20,949©
Cash
1$
The following PHP function can be used to send an HTTP post request and extract emails from an unstructured string. It also includes functions for validating an email address and a domain name.

PHP:
<?php
function sendHttpRequest($url, $data) {
  // Create the context
  $context = stream_context_create(array(
    'http' => array(
      'method' => 'POST',
      'header' => 'Content-type: application/x-www-form-urlencoded',
      'content' => http_build_query($data)
    )
  ));

  // Send the request
  return file_get_contents($url, false, $context);
}

function extractEmails($string) {
  $emails = array();
  preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
  if (isset($matches[0])) {
    foreach ($matches[0] as $email) {
      if (validateEmail($email)) {
        $emails[] = $email;
      }
    }
  }
  return $emails;
}

function validateEmail($email) {
  if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Split the email address into the username and domain
    list($username, $domain) = explode('@', $email);
    // Validate the domain
    if (validateDomain($domain)) {
      return true;
    }
  }
  return false;
}

function validateDomain($domain) {
  if (checkdnsrr($domain, 'MX')) {
    return true;
  }
  return false;
}

?>

That's it! Now you can use these functions to send HTTP post requests, extract emails from unstructured strings, validate email addresses, and validate domain names. 🤓
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Similar threads

Users who are viewing this thread

Top Bottom