3
我的代码是MIME文件附件是不开放
<?php
require_once "Mail.php"; // PEAR Mail package
require_once ('Mail/mime.php'); // PEAR Mail_Mime packge
$from = "<[email protected]>";
$to = "<[email protected]>";
$subject = "Hi!";
$host = "ssl://smtp.googlemail.com";
$port = "465";
$username = "[email protected]";
$password = "example";
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
// attachment
$file = '/var/www/html/formsubmit/TodoList/upload/abc.pdf';
$crlf = "n";
$text="Helllooooo";
$html = "<html> <head> <title>Mail test</title> </head> <body>something</body></html>";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
if($mime->addAttachment($file))
{
echo "Success";
}
else
{
echo "Failed";
}
$body = $mime->get();
$headers = $mime->headers($headers);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
附件是无法甚至下载后打开。
邮件进来的收件箱和附件也there.But附件似乎txt文件。但我实际上是附加一个pdf文件。我使用了SMTP邮件和MIME邮件功能。
请帮我。
该代码看起来正确。您能否将收件人收到的电子邮件的来源(MIME来源)添加到您的问题中? – PeterK
我没有给你。请说清楚 –
代码看起来是正确的,所以它并没有真正告诉我们电子邮件出了什么问题。然而,电子邮件“源代码”(a.k.a.MIME源或.EML文件)可以提供有用的线索。假设收件人邮箱位于Gmail,您可以使用“显示原始”菜单来获取电子邮件源。其他电子邮件客户端通常提供类似的功能 – PeterK