使用php发送带有附件的邮件 [英] sending an mail with attachment using php

查看:201
本文介绍了使用php发送带有附件的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码 - 邮件附件..........但我收到一个错误

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

<?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.";}
    ?>

但是当我运行这个代码我得到一个错误为解析错误:语法错误,意外的@在C:\wamp\www\working\mail1.php在线3.....如何解决这个........

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

推荐答案

你正在使用...而不是引号...。看起来像从网页上复制的代码将引号转换成花式引号并粘贴在文本文件中。

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.

替换所有出现的

这篇关于使用php发送带有附件的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆