로컬 서버에 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
참고 새로운 오류 표시가있다 : 나는 실행하려고 할 때이 오류를 얻을 수 하지만 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";
}
기억, 당신의 코드는 모든 라인 전에 4 개 공간을 필요로한다. 게시 한 후 항상 게시물을보고 명백한 실수를 수정하십시오. –
syntax highlighter가 이미 문제를 보여줍니다 – Ghost
@Ghost 웹 서버에서 코드가 제대로 실행되지만 로컬 호스트로 실행하려고하면 오류가 나타납니다 – user4212650