How to add or create an event in google calendar PHP


The below URL of Google Calender helps us create an event in google calendar.

https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20220112T180000Z%2F20220112T200000Z&details=My First going to happend at Mumbai&location=Mumbai&text=Welcome to My First Event

Let me explain the parameter pass in this URL:

Parameter

  1. action: Template (By Default)
  2. dates: From Time and To Time of event
  3. details: Details of the event
  4. location: Where the event is going to happen
  5. text: Title of the event

Example

<!DOCTYPE html>
<html>
<body>

<a href="https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20220112T180000Z%2F20220112T200000Z&details=My First going to happend at Mumbai&location=Mumbai&text=Welcome to My First Event" target="_blank" style="color: blue; text-decoration: underline;">Add to Google</a>

</body>
</html>

By clicking on the URL it will redirect to the google calendar page if you are on the web and if you are mobile device then it redirects to the calendar app of google.

In PHP instead of hardcoding you have to pass the data dynamically to the parameter.

Example

<!DOCTYPE html>
<html>
<body>

<a href="https://calendar.google.com/calendar/render?action=TEMPLATE&dates=$dates&details=$details&location=$location&text=$title" target="_blank" style="color: blue; text-decoration: underline;">Add to Google</a>

</body>
</html>