Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

email - sending an mail with attachment using php

i have got this code - mail with attachment.......... but i get an error

<?php
    $name = "Reviewbox";
    $email = "[email protected]";
    $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 .= "
MIME-Version: 1.0
" .
    "Content-Type: multipart/mixed;
" .
    " boundary="{$mime_boundary}"";

    $message = "This is a multi-part message in MIME format.

" .
    "-{$mime_boundary}
" .
    "Content-Type: text/plain; charset="iso-8859-1
" .
    "Content-Transfer-Encoding: 7bit

" .

    $message .= "

";

    $data = chunk_split(base64_encode($data));

    $message .= "–{$mime_boundary}
" .
    "Content-Type: {$fileatttype};
" .
    " name="{$fileattname}"
" .
    "Content-Disposition: attachment;
" .
    " filename="{$fileattname}"
" .
    "Content-Transfer-Encoding: base64

" .
    $data . "

" .
    "-{$mime_boundary}-
";

    if(mail($to, $subject, $message, $headers)) {
        echo "The email was sent.";
    }else {echo "There was an error sending the mail.";}
    ?>

but when i run this code i get an error as "Parse error: syntax error, unexpected '@' in C:wampwwwworkingmail1.php on line 3"..... how to solve this ........

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're using “...” instead of quotes "...". Looks like code copied from a web page that transforms quotes into "fancy quotes" and pasted in a text file.

Replace all occurrences of and with ".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...