Jump to content

Getting the mx record of a host.


GoodVibe

Recommended Posts

What does the documentation say?

 

And once you've learned how to use getmxrr(), realize that even if there isn't a record it just means that you should assume the website server also acts as a mail server. (That is, a lack of an MX record simply means there isn't a dedicated MX record.)

Link to comment
Share on other sites

hostname

The Internet host name.

 

mxhosts

A list of the MX records found is placed into the array mxhosts.

 

weight

If the weight array is given, it will be filled with the weight information gathered.

 

 

 

Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred.

 

The thing that confuses me is that i see that mxhosts is the array that will give me the mxhosts, but then the return value says that it only does true/false. So I am a little confused as to how call that array with the values if I am just passing it as a parameter.

 

To Muddy: The list of hosts I have should not have more than one mx record, and if they do, I only care to see the first one, so that method that you posted might work.

Link to comment
Share on other sites

this is lifted from the manual page:

//Jay 11-Sep-2007 05:10
//As stated, some of the code listed below will have trouble with multiple equal weights, such as if you query gmail.com. The following code will prevent that by switching the key/values.

<?php

// Get the records
getmxrr("gmail.com", $mx_records, $mx_weight);

// Put the records together in a array we can sort
for($i=0;$i<count($mx_records);$i++){
    $mxs[$mx_records[$i]] = $mx_weight[$i];
}

// Sort them
asort ($mxs);

// Since the keys actually hold the data we want, just put those in an array, called records    
$records = array_keys($mxs);

// Simply echoes all the stuff in the records array    
for($i = 0; $i < count($records); $i++){
    echo $records[$i];
    echo '<br>';
}

?>

If you wanted to get the weight, you would use "array_values($mxs);" instead of "array_keys($mxs);".

Hope this helps some people.

 

it shows how to get the info you want., I still think using the get_dns_record() would be easier. and using fsock_open() seems to be the preffered method to varify an actual domain as having a mail server.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.