-2

我有一个用于发送带有电子邮件附件的联系表单内容的代码,但在我的查询中,竞争没有显示在电子邮件正文中,所以我选择在标题中显示它,所以请帮忙弄清楚......

 <?php 
 // Settings
 $name = "A";
 $email = "a@q.com";
 $email2 = "v@c.in";
 $to = "$name <$email>,<$email2>";
 $from = $_POST["EEmail"]; 
 $subject2 = "message from contact page";
 $name1 = $_POST["SName"];
 $phone = $_POST["Pphone"];
 $subject1 = $_POST["txtSubject"];
 $description = nl2br($_POST["txtDescription"]);
 $fileatt = ".docx";
 $fileatttype = "application/docx";
 $fileattname = $_FILES["fileAttach"]["name"];
 $headers = "From: $from";
 $subject = "name:$name1,"."Phone:$phone,"."Email
            Id:$from,"."Subject:$subject1,"."Comment:$description.";

 $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}\"";

 $body = "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" .

 $data = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]  ["tmp_name"])));
 $body .= "--{$mime_boundary}\n" .
 "Content-Type: {$fileatttype};\n" .
 " name=\"{$fileattname}\"\n" .
 "Content-Disposition: attachment;\n" .
 " filename=\"{$fileattname}\"\n" .
 "Content-Transfer-Encoding: base64\n\n" .
 "\n\n" ."-{$mime_boundary}-\n";

  // Send the email
 mail($to, $subject,  $headers , $body);
 ?>
4

2 回答 2

0

一方面,你把你的位置$headers$body位置搞混了。

你有:

mail($to, $subject,  $headers , $body);

它应该在哪里:

mail($to, $subject,  $body, $headers);

正文必须成为标题。

根据 PHP 手册http://php.net/manual/en/function.mail.php

于 2013-11-12T12:52:06.763 回答
0

使用 phpmailer https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php

如何使用:

<?php
include("class.phpmailer.php");

$mail = new PHPMailer();

$mail->From = "abc@xyz.com";
$mail->FromName = "My Name";
$mail->AddAddress("recipient@gmail.com");

$mail->AddAttachment("uploads/".$profile_photo_name);    //Path to the file to be attached

$mail->IsHTML(true);                //Set the email type to rich HTML

$mail->Subject = "Your subject";
$mail->Body = "Your email body";    //Body for rich HTML mail

if($mail->Send())               //Send email
{
    echo "Mail sent";
}    
else
    echo "Failure";
?>
于 2013-11-12T12:39:21.247 回答