[英]send mail via php to microsoft exchange
i have function to send mail with attachment to microsoft exchange server.我有 function 可以将带附件的邮件发送到 Microsoft Exchange 服务器。 My problem is that when I wanna to add attachment the whole message part is adding my text to attachment source.
我的问题是,当我想添加附件时,整个消息部分正在将我的文本添加到附件源。 When I save attachment to body section of mail, my attachment source is wrote down in email body instead of creating an attachment.
当我将附件保存到邮件正文部分时,我的附件来源被记在 email 正文中,而不是创建附件。 Belowe is my source.
下面是我的消息来源。
$eol = "\r\n";
$boundary = md5(time());
$mail = "explame@explame.com";
$headers = "From: no-replay@explame.com".$eol;
$headers .= "MIME-Version: 1.0".$eol; //utworzenie headera wiadomosci
$headers .= "Content-type: multipart/alternative; charset=utf-8".$eol;
$headers .= "Message-ID:< TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$boundary."\"".$eol;
$headers .= "--$boundary".$eol;
$headers .= "Content-Type: text/plain; charset=utf-8".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol;
$headers .= "--$boundary--".$eol.$eol;
if ($file != ''){
$handle = fopen($file['tmp_name'], 'rb');
$f_content = fread($handle, $file['size']);
$attachment = chunk_split(base64_encode($f_content));
fclose($handle);
$content .= "--$boundary".$eol;
$content .= "Content-type: ".$file['type'].'; '.'name="'.$file['name'].'"'.$eol;
$content .= 'Content-Disposition: attachment; filename="'.$file['name'].'"'.$eol.$eol;
$content .= "Content-Transfer-Encoding: base64".$eol;
$content .= $attachment.$eol.$eol;
$content .= "--$boundary--".$eol.$eol;
}
mail($mail, 'title', $content, $headers)
i think I tried everything but nothing works for me.我想我什么都试过了,但对我没有用。 :(
:(
a really good PHP lib for sending mail (especially for dealing with attachments) is the phpmailer class.一个非常好的 PHP 用于发送邮件(特别是用于处理附件)的库是 phpmailer class。
You can find it here: http://code.google.com/a/apache-extras.org/p/phpmailer/你可以在这里找到它: http://code.google.com/a/apache-extras.org/p/phpmailer/
EDIT - the above link is to the old project, it's now hosted on Github and more regularly maintained: https://github.com/PHPMailer/PHPMailer编辑 - 上面的链接是旧项目,它现在托管在 Github 上并且更定期维护: https://github.com/PHPMailer/PHPMailer
And an example of how to use it to send an attachment:以及如何使用它发送附件的示例:
include("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->SetFrom('from@mydomain.com');
$mail->AddReplyTo('from@mydomain.com'); //set from & reply-to headers
$mail->AddAddress('to@exchangeserver.com'); //set destination address
$mail->Subject="some subject"; //set subject
$mail->Body="some body HTML <br/><br/>"; //set body content
$mail->AddAttachment('filepath', 'filename'); //attach file
$mail->AltBody = "Can't see this message? Please view in HTML\n\n";
$mail->Send();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.