I get an Error: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp64\www\stage\views\mailtest.php on line 125
I didn't know how to modified the port. I had another code for sending and recieve mails and it's worked but now i need to create an event Calendar with sending mail.
function sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location)
{
$domain = 'hotmail.com';
//Create Email Headers
$mime_boundary = "----Meeting Booking----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">
";
$headers .= "Reply-To: ".$from_name." <".$from_address.">
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"
";
$headers .= "Content-class: urn:content-classes:calendarmessage
";
//Create Email Body (HTML)
$message = "--$mime_boundary
";
$message .= "Content-Type: text/html; charset=UTF-8
";
$message .= "Content-Transfer-Encoding: 8bit
";
$message .= "<html>
";
$message .= "<body>
";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>
";
$message .= "</html>
";
$message .= "--$mime_boundary
";
$ical = 'BEGIN:VCALENDAR' . "
" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "
" .
'VERSION:2.0' . "
" .
'METHOD:REQUEST' . "
" .
'BEGIN:VTIMEZONE' . "
" .
'TZID:Eastern Time' . "
" .
'BEGIN:STANDARD' . "
" .
'DTSTART:20091101T020000' . "
" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "
" .
'TZOFFSETFROM:-0400' . "
" .
'TZOFFSETTO:-0500' . "
" .
'TZNAME:EST' . "
" .
'END:STANDARD' . "
" .
'BEGIN:DAYLIGHT' . "
" .
'DTSTART:20090301T020000' . "
" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "
" .
'TZOFFSETFROM:-0500' . "
" .
'TZOFFSETTO:-0400' . "
" .
'TZNAME:EDST' . "
" .
'END:DAYLIGHT' . "
" .
'END:VTIMEZONE' . "
" .
'BEGIN:VEVENT' . "
" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "
" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "
" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "
" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."@".$domain."
" .
'DTSTAMP:'.date("Ymd\TGis"). "
" .
'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "
" .
'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "
" .
'TRANSP:OPAQUE'. "
" .
'SEQUENCE:1'. "
" .
'SUMMARY:' . $subject . "
" .
'LOCATION:' . $location . "
" .
'CLASS:PUBLIC'. "
" .
'PRIORITY:5'. "
" .
'BEGIN:VALARM' . "
" .
'TRIGGER:-PT15M' . "
" .
'ACTION:DISPLAY' . "
" .
'DESCRIPTION:Reminder' . "
" .
'END:VALARM' . "
" .
'END:VEVENT'. "
" .
'END:VCALENDAR'. "
";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."
";
$message .= "Content-Transfer-Encoding: 8bit
";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
return ($mailsent)?(true):(false);
}
$from_name = "Omar Krichene";
$from_address = "krichene30@hotmail.com";
$to_name = "Omar Krichene";
$to_address = "krichen30@gmail.com";
$startTime = "11/07/2018 18:00:00";
$endTime = "11/07/2018 19:00:00";
$subject = "My Test Subject";
$description = "My Awesome Description";
$location = "Krichene House";
sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location);