2012-03-29 156 views
1

任何人都可以帮我?我试图发送附件的电子邮件发送电子邮件,但电子邮件发送编码格式我认为问题是与头部可以任何一个给我的工作代码..有很多现成的代码在网上我试过他们没有所有的人,但工作关于电子邮件附件在php

+0

尝试使用一些好的库,如phpmailer ... – 2012-03-29 13:57:49

+0

把一些代码,如果你需要我们找到一个解决方案... ... – 2012-03-29 13:58:54

回答

0

您可以使用PHPMailer的http://code.google.com/a/apache-extras.org/p/phpmailer/

下载中心链接:http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/detail?name=PHPMailer_5.2.1.zip&can=2&q=

$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

try { 
    $mail->AddReplyTo('[email protected]', 'First Last'); 
    $mail->AddAddress('[email protected]', 'John Doe'); 
    $mail->SetFrom('[email protected]', 'First Last'); 
    $mail->AddReplyTo('[email protected]', 'First Last'); 
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced'; 
    $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically 
    $mail->MsgHTML(file_get_contents('contents.html')); 
    $mail->AddAttachment('images/phpmailer.gif');  // attachment 
    $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment 
    $mail->Send(); 
    echo "Message Sent OK</p>\n"; 
} catch (phpmailerException $e) { 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer 
} catch (Exception $e) { 
    echo $e->getMessage(); //Boring error messages from anything else! 
} 

感谢

:)