<?php$dtStart = '20090825T131415Z';//yyyymmddThhmmssZ
$dtEnd = '20090826T151617Z';
//--------------------
//create text file
$ourFileName = "icsFile/calendar.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file1");
fclose($ourFileHandle);
//
//edit temp file
$myFile = "icsFile/calendar.txt";
$fh = fopen($myFile, 'w') or die("can't open file2");$stringData = "
BEGIN:VCALENDAR\n
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN\n
VERSION:2.0\n
METHOD:REQUEST\n
BEGIN:VEVENT\n
ORGANIZER:MAILTO:[email protected]\n
DTSTAMP:".date('Ymd').'T'.date('His')."\n
DTSTART:$dtStart\n
DTEND:$dtEnd\n
TRANSP:OPAQUE\n
SEQUENCE:0\n
UID:".date('Ymd').'T'.date('His')."-".rand()."-domain.com\n
SUMMARY:do something someware\n
DESCRIPTION: This is just a test\n
PRIORITY:5\n
X-MICROSOFT-CDO-IMPORTANCE:1\n
CLASS:PUBLIC\n
END:VEVENT\n
END:VCALENDAR";
fwrite($fh, $stringData);
fclose($fh);
//email temp file
$fileatt = "icsFile/calendar.txt"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "ical.ics"; // Filename that will be used for the file as the attachment $email_from = "[email protected]"; // Who the email is from
$email_subject = "Email test"; // The Subject of the email
$email_message = "this is a sample message \n\n next line \n\n next line"; // Message that the email has in it $email_to = "[email protected]"; // Who the email is too $headers = "From: ".$email_from; $file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file); $semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n"; $ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) { } else {
die("Sorry but the email could not be sent. Please go back and try again!");
}?>
结果是:Sorry but the email could not be sent. Please go back and try again!由于刚接触php,看代码也不是很明白,谢谢高手能给指点一二 :)
$email_to = "[email protected]";
等等这些东西换成可用的邮箱了吗
如果可用的话,可能还得需要配置smtp服务器吧。
好像在什么php.ini
http://www.phpchina.com/html/21/32421-12005.html
你看看吧。
如果你用现在的方法,你看一下上面的连接吧。
<?
$to = "[email protected]";
$subject = "ZDNet Developer article";
$msg = "I completely understand SMTP servers now!";
$headers = "From:[email protected]\r\nReply-To:[email protected]";
mail("$to", "$subject", "$msg", "$headers");
echo "finished!";
?>
用这段代码试着发了下,应该是服务器的事Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in F:\PHPSystem\myphp\mail1.php on line 6
finished
因为不只是发邮件,是发outlook的日历约会,不能直接用网上那些发邮件的类,我发邮件是试着能不能发出去,如果邮件能发出去,发日历形式的应该也没问题了
finished!
你 ini文件改了以后,需要重新读。所以可能需要重启。
<?php
phpinfo();
?>
找到了用到的那个ini文件
谢谢!
你用别的邮件服务器不行。
难道需要建本地smtp服务器吗。