Jump to content

Email validator code not working


Recommended Posts

i would like to create a hook to validate the customer email id when customer register the profile on whmcs. i created the following code. i need to validate the email and save the result to a txt file. but its not working. so can you please help    me.

Api mentioned on this code is dummy.

<?php
use WHMCS\View\Menu\Item as MenuItem;
use WHMCS\Database\Capsule;

add_hook('ClientAdd', 1, function($vars) {
    // Perform hook code here...

    $firstname = $vars->firstname;
    $sourceemail = $vars->email;
    $sourceuserid = $vars->client_id;
    
    // Prepare API URL
    $api_key = "myapi";
    $email = urlencode($sourceemail);
    $ip_address = "13.16.6.253"; // Assuming this is a static IP address
    $api_url = "https://api.zerobounce.net/v2/validate?api_key=$api_key&email=$email&ip_address=$ip_address";

    // Initialize cURL session
    $ch = curl_init();
    
    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $api_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    // Execute cURL session
    $response_json = curl_exec($ch);
    
    // Close cURL session
    curl_close($ch);
    
    // Decode JSON response
    $response = json_decode($response_json);
    
    // Extract status from response
    $status = $response->status;

    // Save $status to a text file
    $filename = $sourceemail . '.txt';
    $file_content = "Status: $status\n";
    file_put_contents($filename, $file_content);

    // Optional: Display the status
    echo "Status for $sourceemail: $status";

    // Optional: Display any errors
    if ($status !== 'valid') {
        echo "Validation failed for $sourceemail";
    }

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
});

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated