【发布时间】:2011-05-30 10:41:00
【问题描述】:
我有这个代码 - 带有附件的邮件.......但我收到一个错误
<?php
$name = "Reviewbox";
$email = "jmaster@gmail.com";
$to = "$name <$email>";
$from = "Reviewbox ";
$subject = "Here is your attachment";
$fileatt = "doc.pdf";
$fileatttype = "application/pdf";
$fileattname = "newname.pdf";
$headers = "From: $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}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"-{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "–{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$mime_boundary}-\n";
if(mail($to, $subject, $message, $headers)) {
echo "The email was sent.";
}else {echo "There was an error sending the mail.";}
?>
但是当我运行此代码时,我收到错误消息“解析错误:语法错误,第 3 行 C:\wamp\www\working\mail1.php 中的意外 '@'”..... 如何解决这…………
【问题讨论】:
-
@etbal ya 那不是我的代码.....我从网上拿的..如何解决这个......
-
答案在下面@Radu 的答案中。请不要说你写了代码然后说你是从网上复制的......
-
获取一个带有php语法高亮的编辑器,不要使用记事本...