我有一个收集用户信息的表格
Name
Age
CV
然后我通过jquery提交该表单以发送电子邮件
我有以下代码
var a= $('#a').attr('value');
var b= $('#b').attr('value');
$j.ajax({
type: "POST",
url: "sendemail.php",
data: "a="+ a +"&b="+ b,
success: function(html){
.............
此功能有效,但我无法找到验证文件为MSWORD或PDF然后附加和发送电子邮件的方法。
我正在使用php mail()函数发送电子邮件
$Headers = "MIME-Version: 1.0\n";
$Headers .= "Content-type: text/html; charset=iso-8859-1\n";
$Headers .= "From: ".$FromName." <".$FromEmail.">\n";
$Headers .= "Reply-To: ".$ReplyTo."\n";
$Headers .= "X-Sender: <".$FromEmail.">\n";
$Headers .= "X-Mailer: PHP\n";
$Headers .= "X-Priority: 1\n";
$Headers .= "Return-Path: <".$FromEmail.">\n";
if(mail($ToEmail, $Subject, $Content, $Headers) == false) {
echo "2";
}
else
{
echo "1" ;
}
my basic question is:
1. how to validate file (only MSWORD and PDF)
2. send file to sendemail.php via AJAX to attach with email.
由于
答案 0 :(得分:2)
您可以使用PHPMailer库非常好地处理电子邮件。您可以使用此库一次向多个收件人发送带附件的电子邮件。
答案 1 :(得分:0)
包含在您的函数PHPMailer
中试试这个:
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsMail();
$mail->From="mailer@example.com";
$mail->FromName="My site's mailer";
$mail->Sender="mailer@example.com";
$mail->AddReplyTo("replies@example.com", "Replies for my site");
$mail->AddAddress("email@example.com");
$mail->Subject = "Your invoice";
$mail->IsHTML(false);
$mail->AddAttachment('files/invoice-user-1234.pdf', 'invoice.pdf');
$mail->Body = "Please find your invoice attached.";
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
echo "Letter is sent";
}