How to auto submit a Sitemap to Google using PHP

Written by Ian Carnaghan · 35 sec read >

This can be done via a ping service from Google Webmaster Tools

Add the following PHP function 

	function submitSitemap($site)
	        $url = ''.htmlentities($site.'/sitemap.xml');
	        $response = file_get_contents($url);
	          echo $response;
	          echo "Failed to submit sitemap";

Now you need to call the above function as example below to submit your sitemap to Google.

submitSitemap(''); //Replace with your website

Once the sitemap has been submitted the following message will be returned

Sitemap Notification Received

Your Sitemap has been successfully added to our list of Sitemaps to crawl. If this is the first time you are notifying Google about this Sitemap, please add it via so you can track its status. Please note that we do not add all submitted URLs to our index, and we cannot make any predictions or guarantees about when or if they will appear.

Last Updated On March 22, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. Profile

Leave a Reply

Notify of