<?php
$file = $_FILES["file"]["tmp_name"];
$file1 = $_FILES["file1"]["tmp_name"];
$attachment_path = $file;
$attachment_path1 = $file1;
$body = "some text";
include("class.phpmailer.php");
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Set who the message is to be sent from
$mail->SetFrom('mail@example.com', $username);
//Set who the message is to be sent to
$mail->AddAddress('mail@example.com', 'Ticket Relief');
//Set the subject line
$mail->Subject = 'Inquiry from website by Form Fillup';
//Replace the plain text body with one created manually
$mail->Body = $body;
//Attach an image file
$mail->AddAttachment($attachment_path, "attachment1", "base64", "application/octet-stream");
$mail->AddAttachment($attachment_path1, "attachment1", "base64", "application/octet-stream");
//Send the message, check for errors
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Email has been sent! Please <a href='index.php'>Click Here </a> to go back to home page";
}
?>
and html code
和HTML代码
<form action="functions.php" method="post" enctype="multipart/form-data">
<div class="outer1">
<label> Please Choose File</label>
<input type="file" class="span4" name="file">
</div>
<div class="outer1">
<label> Please Choose File</label>
<input type="file" class="span4" name="file1">
</div>
<div class="outer1">
<input type="submit" class="submit btn btn-success btn-large pull-right" value="Submit">
</div>
</form>
- I am receiving email but cannot open attached file. its in unknown format.
- if file is more than 200kb then its take 40-45 sec to send mail and if its more than 600kb it takes more than 1 min to process
我收到电子邮件但无法打开附件。它的格式未知。
如果文件超过200kb,则发送邮件需要40-45秒,如果超过600kb则处理时间超过1分钟
need help on these issues
在这些问题上需要帮助
1 个解决方案
#1
0
First, validate that the upload actually succeeded. Try this:
首先,验证上传实际上是否成功。试试这个:
if(isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK &&
isset($_FILES['file1']) && $_FILES['file1']['error'] == UPLOAD_ERR_OK
) {
$mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
$mail->AddAttachment($_FILES['file1']['tmp_name'], $_FILES['file1']['name']);
}
else {
// Do something else, upload is not successful
}
You should set a file name as second argument, not just a string like attachment1
您应该将文件名设置为第二个参数,而不仅仅是像attachment1这样的字符串
AddAttachment($path, $filename, ...
//^ put here the file name like $_FILES['file1']['name']
#1
0
First, validate that the upload actually succeeded. Try this:
首先,验证上传实际上是否成功。试试这个:
if(isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK &&
isset($_FILES['file1']) && $_FILES['file1']['error'] == UPLOAD_ERR_OK
) {
$mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
$mail->AddAttachment($_FILES['file1']['tmp_name'], $_FILES['file1']['name']);
}
else {
// Do something else, upload is not successful
}
You should set a file name as second argument, not just a string like attachment1
您应该将文件名设置为第二个参数,而不仅仅是像attachment1这样的字符串
AddAttachment($path, $filename, ...
//^ put here the file name like $_FILES['file1']['name']