douyi0902 2018-07-10 07:56
浏览 199

导出日历和发送邮件Outlook PHP

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);
  • 写回答

1条回答

  • dph23577 2018-07-10 08:03
    关注

    The script is not able to connect to the SMTP server. Have you checked if an SMTP server is running on the localhost or the computer the script is running from at port 25? If not you'll need to provide a working SMTP server address and login to it.

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?