dadamssg87 Posted November 30, 2011 Share Posted November 30, 2011 i use file_get_contents() to grab entire web pages to send as html emails. How can i error check that the url i use in file_get_contents() actually exists. I thought i could put it in an if statement like cURL but that doesn't work. <?php if($email_body = file_get_contents($url)) { $config['mailtype'] = 'html'; $this->email->initialize($config); $this->email->from('[email protected]', 'Testing'); $this->email->to($email); $this->email->subject("Confirm Reply-To Email"); $this->email->message($email_body); $this->email->send(); } Link to comment https://forums.phpfreaks.com/topic/252139-if-file_get_contents-fails/ Share on other sites More sharing options...
scootstah Posted November 30, 2011 Share Posted November 30, 2011 Something like this should work: $curl = curl_init('http://example.com'); curl_setopt($curl, CURLOPT_NOBODY, true); curl_exec($curl); $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($http_status == 200) { // good to go } Link to comment https://forums.phpfreaks.com/topic/252139-if-file_get_contents-fails/#findComment-1292693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.