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.
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.
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.