Jump to content

Sending Attachments via e-mail.


PdVortex

Recommended Posts

Hello, wondering if anyone can help me with an issue im having?

 

Im trying to get this form to work it sends an e-mail and included any attachments then user wants to add to it.

 

Problem is when they submit the form they get these errors

 

Warning: Variable passed to each() is not an array or object in C:\Inetpub\vhosts\cavendishknights.com\httpdocs\payment.php on line 70

 

Warning: Variable passed to each() is not an array or object in C:\Inetpub\vhosts\cavendishknights.com\httpdocs\payment.php on line 88

 

Warning: Variable passed to each() is not an array or object in C:\Inetpub\vhosts\cavendishknights.com\httpdocs\payment.php on line 117

Sorry the server was unable to upload the files...

 

This is the code im using :

 

<?php
   require("class.phpmailer.php");
//Variables Declaration
   $name = "the Submitter";
   $email_subject = 'New Escort Application!';
   $email_from = "tony@cavnedishknights.com";
   $Email_to = 'cavendishknights@cavendishknights.com';
   $email_from = stripslashes($_POST['FullName']);
   $postcode = stripslashes($_POST['PostCode']);
   $fulladdress = stripslashes($_POST['FullAddress']);
   $MobileNumber = stripslashes($_POST['MobileNumber']);
   $YearsAtAddress = stripslashes($_POST['YearsAtAddress']);
   $PreviousAddress = stripslashes($_POST['PreviousAddress']);
   $Age = stripslashes($_POST['Age']);
   $DOB = stripslashes($_POST['DOB']);
   $Height = stripslashes($_POST['Height']);
   $Weight = stripslashes($_POST['Weight']);
   $Build_ = stripslashes($_POST['Build_']);
   $Build_2 = stripslashes($_POST['Build_2']);
   $Build = stripslashes($_POST['Build']);
   $Occupation = stripslashes($_POST['Occupation']);
   $EducationalBackground = stripslashes($_POST['EducationalBackground']);
   $Hobbies = stripslashes($_POST['Hobbies']);
   $Intrests = stripslashes($_POST['Intrests']);
   $PleaseDescribeYourself = stripslashes($_POST['PleaseDescribeYourself']);
   $CRB_0= stripslashes($_POST['CRB_0']);
   $CRB_1 = stripslashes($_POST['CRB_1']);
   $CRB_2 = stripslashes($_POST['CRB_2']);
   $Sign = stripslashes($_POST['Sign']);
   $Email_msg = "Message from: $from\n\nFull Address: $fulladdress\n\nPost Code: $postcode\n\nMobile Number: $MobileNumber\n\nYears At Address: $YearsAtAddress\n\nPrevious Address: $PreviousAddress\n\nAge : $Age\n\nDOB: $DOB\n\nHeight: $Height\n\nWeight: $Weight\n\nBuild : $Build_\n\nBuild: $Build_2\n\nBuild: $Build\n\nOccupation: $Occupation\n\nEducational Background : $EducationalBackground\n\nHobbies : $Hobbies\n\nIntrests : $Intrests\n\nPlease Describe Yourself : $PleaseDescribeYourself\n\nI have a current CRB form and attach a copy and payment of 7.50 (Post only) : $CRB_0\n\nI do not have a current CRB form and attach payment of 28.00 (Post or E-mail) : $CRB_1\n\nI am a foreign national and attach paymentof 36.00 (Post or E-mail) : $CRB_2\n\nSign : $Sign\n\n";
$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"; // 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);
                                //}
        
    
}
?>

 

Line 70 is this :        strtolower($value);

 

Line 88 is this :        {

 

Line 117 is this :    {

 

Hopefully someone can help me i been at this for hours and i bet its something really simple.

 

Thanks for any help in advance

Link to comment
Share on other sites

Hey thanks for your reply, i have already said what the lines are here they are again :

 

Line 70 is this :        strtolower($value);

 

Line 88 is this :        {

 

Line 117 is this :    {

 

Sorry i don't know how to highlight the code.

 

Thanks for any help in advance

Link to comment
Share on other sites

I'm having the same problem with the same error messages with a similar script.

 

I think your line numbers are off:  I think the offending code actually is:

 

    while(list($key,$value) = each($_FILES[images][type]))

 

while(list($key,$value) = each($_FILES[images])){

 

while(list($key,$value) = each($_FILES[images][name])){

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.