Please help me here, I will try give you as much information as possible!
I have been trying to set up an email form with the feature to upload a file and attach it with the email.
I have got it successfully working but only with files of around 3mb. Now, I have checked everything I could think of with regards to why larger files will not work. I have called my hosting company and they have said it is not the server set up but something to do with the script itself. Whether that is true or not I do not know.
I am using two pages alongside the
PHPMailer class.
http://www.pixelpractice.com/work/aep/email/emailform.php
Very simple form pointing to attach.php with the file path in an array.
http://www.pixelpractice.com/work/aep/email/attach.php
Uploads, checks and emails the email with attachement, includes the phpmailer class.
I got the attach.php script from
here
http://zainal.wordpress.com/category/php-file-upload/
Hosting.
www.1and1.co.uk
SMTP Setting: smtp.1and1.com
PHP Setup
http://www.webfroot.co.uk/email/phpinfo.php
Right, as I have mentioned with a file around 2.5 / 3mb there is no problem, it really works well. Now when I try to add a 6mb JPG file the file uploads to the server but the send email function does not seem to process nor does an error occur.
Once the function to check the upload is successful it is calling the function to send the email but nothing happens.
I have turned on SMTP error notification to help diagnose. It should display "Message has been sent" at the end when sent, but seems to hand at "file successfully uploaded"
Attach.php
PHP Code:
<?php
require("class.phpmailer.php");
//Variables Declaration
$name = "the Submitter";
$email_subject = "Feed Back";
$Email_msg ="A visitor submitted the following :\n";
$Email_to = "ryank1978@hotmail.com"; // the one that recieves the email
$email_from = "ryank1978@hotmail.com";
$dir = "uploads/$filename";
chmod("uploads",0777);
$attachments = array();
checkType();
//------Check TYPE------\\
function checkType() {
while(list($key,$value) = each($_FILES[images][type])){
strtolower($value);
if($value != "image/jpeg" AND $value != "image/pjpeg" AND $value != "") {
exit('Sorry , current format is <b>'.($value).'</b> ,only Jpeg or jpg are allowed.');
}
}
checkSize();
}
//-------END OF Check TYPE--------\\
//---CheckSizeFunction ---\\
function checkSize(){
global $result, $MV ,$errors,$BackLink;
while(list($key,$value) = each($_FILES[images][size]))
{
$maxSize = 8000000;
if(!empty($value)){
if ($value > $maxSize) {
echo"Sorry this is a very big file .. max file size is $maxSize Bytes = 5 MB";
exit();
}
else {
$result = "File size is ok :)<br>";
}
}
}
uploadFile();
}
//-------END OF Check Size--------\\
//==============upload File Function============\\
function uploadFile() {
global $attachments;
while(list($key,$value) = each($_FILES[images][name]))
{
echo("just trying to send it!!!");
if(!empty($value))
{
$filename = $value;
array_push($attachments, $filename);
$dir = "uploads/$filename";
chmod("uploads",0777);
$success = copy($_FILES[images][tmp_name][$key], $dir);
}
}
if ($success) {
echo " Files Uploaded Successfully<BR>";
SendIt();
}else {
exit("Sorry the server was unable to upload the files...");
}
}
//======================================================================== PHP Mailer With ATtachment Func ===============================\\
function SendIt() {
global $attachments,$name,$Email_to,$Email_msg,$email_subject,$email_from;
$mail = new PHPMailer();
$mail->IsSMTP();// send via SMTP
$mail->Host = "smtp.1and1.com"; // SMTP servers
$mail->SMTPAuth = false; // turn on/off SMTP authentication
$mail->From = $email_from;
$mail->FromName = $name;
$mail->AddAddress($Email_to);
$mail->AddReplyTo($email_from);
$mail->WordWrap = 50;// set word wrap
foreach($attachments as $key => $value) { //loop the Attachments to be added ...
$mail->AddAttachment("uploads"."/".$value);
}
$mail->Body = $Email_msg."Name : ".$name."\n";
$mail->IsHTML(false);// send as HTML
$mail->Subject = $email_subject;
if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
// after mail is sent with attachments , delete the images on server ...
//foreach($attachments as $key => $value) {//remove the uploaded files ..
// unlink("uploads"."/".$value);
//}
}
?>
Help on this will be most appreciated, I have spent days on this now.