如何将附件添加到x-mailer?

时间:2018-10-30 11:11:05

标签: php

如何使用x-mailer向此PHP添加附件?

$headers = "From: ($full_name)".
' '.$email_from."\r\n" .
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
"Reply-To: ($reply_to)" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>

我填写了为什么它不起作用?

<?php
require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com';                 // Specify main and backup server
$mail->Port = 587;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME';                // SMTP username
$mail->Password = 'MANDRILL_APIKEY';                  // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Your From name';
$mail->AddAddress('josh@example.net', 'Josh Adams');  // Add a recipient
$mail->AddAddress('ellen@example.com');               // Name is optional

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

显示“ HTTP 500错误 奇怪…网站无法显示此页面 该站点可能正在维护或可能存在编程错误。”     回显“消息已发送”;

1 个答案:

答案 0 :(得分:0)

您必须创建$ email_message,如下所示:

$headers = "From: ($full_name)".' '.$email_from."\r\n";
$headers .= "Content-Type: multipart/related; boundary="emailsectionseparator"; type="text/html"\r\n";
"Reply-To: ($reply_to)" . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$email_message = "--emailsectionseparator\r\n";
$email_message.= "Content-Type: text/html; charset="ISO-8859-1"\r\n";
and so on ...

$email_message.= "--emailsectionseparator--\r\n";

mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>

关注这个sheme:

--emailsectionseparator
Content-Type: text/html; charset="US-ASCII"

Here goes the HTML content:


--emailsectionseparator
Filename: <filename>
Content-Type: image/jpeg
Content-Transfer-Encoding: Base64

ABX1JKADFjkad91/291... 50k of base64 data here...

--emailsectionseparator--

并将Content-Header设置为以下内容:

Content-Type: multipart/related; boundary="emailsectionseparator"; type="text/html"