GoodVibe Posted April 17, 2012 Share Posted April 17, 2012 I currently have a list of host addresses. I need to get the mx records for them. I was looking at the documentation, and found the getmxrr(). Would that send back the mx record, or just true if it has one? Quote Link to comment https://forums.phpfreaks.com/topic/261110-getting-the-mx-record-of-a-host/ Share on other sites More sharing options...
requinix Posted April 17, 2012 Share Posted April 17, 2012 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.) Quote Link to comment https://forums.phpfreaks.com/topic/261110-getting-the-mx-record-of-a-host/#findComment-1338136 Share on other sites More sharing options...
Muddy_Funster Posted April 17, 2012 Share Posted April 17, 2012 I think what you are looking for is http://uk3.php.net/manual/en/function.dns-get-record.php (assuming you don't have an array of MX records to work from at this point) Quote Link to comment https://forums.phpfreaks.com/topic/261110-getting-the-mx-record-of-a-host/#findComment-1338138 Share on other sites More sharing options...
GoodVibe Posted April 17, 2012 Author Share Posted April 17, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261110-getting-the-mx-record-of-a-host/#findComment-1338139 Share on other sites More sharing options...
Muddy_Funster Posted April 17, 2012 Share Posted April 17, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261110-getting-the-mx-record-of-a-host/#findComment-1338150 Share on other sites More sharing options...
requinix Posted April 17, 2012 Share Posted April 17, 2012 getmxrr() takes the MX record list and weights by reference. If you give it variables for those two then it will populate them with the values it finds. The true/false is so you can, like, stick it in a condition. Quote Link to comment https://forums.phpfreaks.com/topic/261110-getting-the-mx-record-of-a-host/#findComment-1338159 Share on other sites More sharing options...
GoodVibe Posted April 17, 2012 Author Share Posted April 17, 2012 Ended up using: $mxr = dns_get_record($sub, DNS_MX); So thank you very much Muddy for the suggestion and everyone for the help. Quote Link to comment https://forums.phpfreaks.com/topic/261110-getting-the-mx-record-of-a-host/#findComment-1338237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.