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.

    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建