我的本地服务器上有mail.php。当我尝试运行时,我收到此错误:
Parse error: syntax error, unexpected 'r' (T_STRING) in C:\xampp\htdocs\Email\Mail.php on line 21
修正错误后,会出现新的错误显示
Warning: filesize(): stat failed for /htdocs/Email/CashPickup.xml in C:\xampp\htdocs\Email\Mail.php on line 20
Warning: fopen(/htdocs/Email/CashPickup.xml): failed to open stream: No such file or directory in C:\xampp\htdocs\Email\Mail.php on line 21
Warning: fread() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Email\Mail.php on line 22
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Email\Mail.php on line 23
注意:我的代码在Web服务器上运行时没有错误,但它运行正常但在我运行到localhost后,会显示这些错误。
代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
/* Email Detials */
$mail_to = "email";
$from_mail = "email";
$from_name = "title";
$reply_to = "";
$subject = "subj...";
$message_body = "";
/* Attachment File
Attachment location */
$file_name = "filename.xml";
$path = "\htdocs\Email\";
// Read the file content
$file = $path . $file_name;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
/* Set the email header
Generate a boundary */
$boundary = md5(uniqid(time()));
// Email header
$header = "From: " . $from_mail . " \r\n";
$header .= "Reply-To: " . $reply_to . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
// Multipart wraps the Email Content and Attachment
$header .= "Content-Type: multipart/mixed;\r\n";
$header .= " boundary=\"" . $boundary . "\"";
$message_body .= "This is a multi-part message in MIME format.\r\n\r\n";
$message_body .= "--" . $boundary . "\r\n";
/* Email content
Content-type can be text/plain or text/html */
$message_body .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message_body .= "Content-Transfer-Encoding: 7bit\r\n";
$message_body .= "\r\n";
$message_body .= "$message_body\r\n";
$message_body .= "--" . $boundary . "\r\n";
/* Attachment
Edit content type for different file extensions */
$message_body .= "Content-Type: application/xml;\r\n";
$message_body .= " name=\"" . $file_name . "\"\r\n";
$message_body .= "Content-Transfer-Encoding: base64\r\n";
$message_body .= "Content-Disposition: attachment;\r\n";
$message_body .= " filename=\"" . $file_name . "\"\r\n";
$message_body .= "\r\n" . $content . "\r\n";
$message_body .= "--" . $boundary . "--\r\n";
// Send email
if (mail($mail_to, $subject, $message_body, $header)) {
echo "Sent";
} else {
echo "Error";
}
答案 0 :(得分:2)
是的,我找到了,你正在使用转义字符\
。
检查出来,
$path = "\htdocs\Email\";
应该是
$path = "\\htdocs\\Email\\";
或者更好的是,只需使用/
:
$path = "/htdocs/Email/";