带附件的PHPMailer

时间:2015-12-08 18:24:45

标签: php email phpmailer

所以,我遇到了这段代码的问题。 这是一个获取数据的表单,这是phpmailer片段,我得到错误无法访问文件

$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message= $_REQUEST['message'];
$message= "--$boundary" . PHP_EOL;
$message= "Content-Type: text/html; charset='utf-8'" . PHP_EOL;
$message= "--$boundary" . PHP_EOL;
$tapete=$_REQUEST['tapete'];
$medidas=$_REQUEST['medidas'];
$cliente=$_REQUEST['cliente'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "mucapapipa.br@gmail.com";
$mail->Password = "----";
$mail->Subject   = 'Formulário FacilityCom';
$mail->setFrom = ('mucapapipa.br@gmail.com');
$mail->Body      = 'Tipo e marca: $tapete \nMedidas: $medidas \nCliente:         $cliente\n $from';
$mail->IsHTML(true);
$mail->AddAttachment($file['tmp_name'], $file['name']);
$mail->Send();`

1 个答案:

答案 0 :(得分:0)

这里有很多错误。

不要搞乱边界 - PHPMailer会为你完成所有这些。

$mail->setFrom = ('mucapapipa.br@gmail.com')应为$mail->setFrom('mucapapipa.br@gmail.com')

如果您将代码基于the file upload example provided with PHPMailer,这会有助于显示如何正确处理文件上传。