Jump to content

Email Attachment Help


delniqueworks

Recommended Posts

I created a php file to send an email with two image attachments. The email portion sends the email o.k., but I can't get the attachments to load. The first is my form.

 

<?php

if(!empty($_POST))

{

  // The HTML form handler.

  require "handler.php";

}

 

 

?>

 

 

<script type = "text/javascript">

 

//Validate required

function validateRequired(FIELD, ALERTTEXT)

{

with(FIELD)

{

if(value == null || value == '')

{

alert(ALERTTEXT);

return false;

}

else

{

return true;

};

};

};

 

function validateForm(FORM)

{

with(FORM)

{

if(validateRequired( fName, "You must provide your First Name!") == false) {fName.focus(); return false;};

if(validateRequired( lName, "You must provide your Last Name!") == false) {lName.focus(); return false;};

if(validateRequired( job, "You must provide your Occupation!") == false) {job.focus(); return false;};

if(validateRequired( month, "You must provide your Birthday Month!") == false) {month.focus(); return false;};

if(validateRequired( day, "You must provide your Birthday Day!") == false) {day.focus(); return false;};

if(validateRequired( year, "You must provide your Birthday Year!") == false) {year.focus(); return false;};

if(validateRequired( city, "You must provide your City!") == false) {email.focus(); return false;};

if(validateRequired( state, "You must provide your State!") == false) {email.focus(); return false;};

if(validateRequired( phone, "You must provide your Phone Number!") == false) {email.focus(); return false;};

if(validateRequired( email, "You must provide your Email!") == false) {email.focus(); return false;};

//if(validateRequired( full, "You must provide a Full Body Photo!") == false) {full.focus(); return false;};

//if(validateRequired( hdst, "You must provide a Head Shot Photo!") == false) {hdst.focus(); return false;};

 

};

};

 

 

 

</script>

 

 

<div id="form">

<p>STEP ONE:</p>

<form name="contest" method="post" action="paypal.php" onsubmit="return validateForm(this)" enctype="multipart/form-data" style="margin-left:10px;" >

   

    <div id="aName">

      First Name<span style="color:#F00;">*</span>  

    <input type="text" name="fName" id="fName" style="width:150px;" />

        

      Last Name<span style="color:#F00;">*</span>  

      <input type="text" name="lName" id="lName" style="width:150px;" />       

    

  Occupation<span style="color:#F00;">*</span>  

      <input type="text" name="job" id="job" style="width:150px;" />

        </div>

       

            <div id="location">

            Birthday<span style="color:#F00;">*</span>  

  <input type="text" name="month" maxlength="2" id="month" style="width:30px;" />  / 

        <input type="text" name="day" id="day" maxlength="2" style="width:30px;" />  / 

        <input type="text" name="year" id="year" maxlength="2" style="width:30px;" />  

       

            City<span style="color:#F00;">*</span>  

            <input type="text" name="city" maxlength="20" id="city" style="width:200px;" />

             

            State<span style="color:#F00;">*</span>   <input type="text" name="state" maxlength="2" id="state" style="width:30px;" />

             

            Phone<span style="color:#F00;">*</span>  <input type="text" name="phone" maxlength="14" id="phone" style="width:200px;" />

            </div>

           

        <div id="con contact">

        Email<span style="color:#F00;">*</span>   <input type="text" name="email" id="email" style="width:200px;" />

         

        Website  <input type="text" name="web" id="web" style="width:200px;" />

         

        Facebook  <input type="text" name="facebook" id="facebook" style="width:200px;" />

        </div>

       

            <div id="biog">

            Why Should you be crowned Diva of the Year?<span style="color:#F00; font-size:12px;"> *Limit 350 words</span>

            <br />

        <textarea name="bio" id="bio"  cols="60" rows="10"></textarea>

    </div>

       

<!--<div id="fileUpload">

      <p style="color:#F00; font-style:italic; font-size:12px;">A picture with your application is required. A full length and headshot only. The image must be .jpg</p>

        Full Body Picture<span style="color:#F00;">*</span>  <span style="color:#F00; font-size:12px;">(Max file size 2MB)</span>

<br />

        <input type="hidden" name="MAX_FILE_SIZE" value="102400"  />

        <input type="hidden" name="upload" value="upload" id="upload" >

            <input type="file" name="full" id="full" />

      <br />

          <br />

Head Shot Picture<span style="color:#F00;">*</span>  <span style="color:#F00; font-size:12px;">(Max file size 2MB)</span>

          <br />

            <input type="hidden" name="MAX_FILE_SIZE" value="102400"  />

            <input type="file" name="hdst" id="hdst" />

            <input type="hidden" name="upload" value="upload" id="upload" >

</div>-->

       

        <div id="marketing">

        <input type="checkbox" name="news" id="news" checked="checked"  />  Yes, Please sign me up to receive a monthly newsletter and other email from SizeSexyDivas

        </div>

       

        <div id="done">

        <input type="submit" name="submit" value="Submit" id="submit" >

        </div>

       

        <div id="errorMessage">

<?php

echo "<h3>". $error ."</h3>";

?>

        </div>

        <span style="text-align:center; font-size:10px; color:#999;">For full contest "Rules and Regulations" on the SizeSexyDiva of the Year Contest Click <a href="rules.php" style="color:#900;">Here.</a></span>

</form>

</div>

 

 

This is the function php on the handler.php page:

<?php

 

// Process form fields

$fName = $_POST['fName'];

$lName= $_POST['lName'];

$job = $_POST['job'];

$month = $_POST['month'];

$day = $_POST['day'];

$year = $_POST['year'];

$age = ($month . " / " . $day . " / " . $year);

$city = $_POST['city'];

$location = ($city . ", " . $state);

$state = $_POST['state'];

$phone = $_POST['phone'];

$email = $_POST['email'];

$web = $_POST['web'];

$facebook = $_POST['facebook'];

$bio = $_POST['bio'];

$bio = wordwrap($bio, 70);

$news = $_POST['news'];

 

 

$_POST['fName'] = htmlspecialchars(stripslashes($_POST['fName']));

$_POST['lName'] = htmlspecialchars(stripslashes($_POST['lName']));

$_POST['email'] = htmlspecialchars(stripslashes($_POST['email']));

$_POST['bio'] = htmlspecialchars(stripslashes($_POST['bio']));

$_POST['web']= htmlspecialchars(stripslashes($_POST['web']));

$_POST['facebook']= htmlspecialchars(stripslashes($_POST['facebook']));

$_POST['city']= htmlspecialchars(stripslashes($_POST['city']));

$_POST['state']= htmlspecialchars(stripslashes($_POST['state']));

$_POST['month']= htmlspecialchars(stripslashes($_POST['month']));

$_POST['day']= htmlspecialchars(stripslashes($_POST['day']));

$_POST['year']= htmlspecialchars(stripslashes($_POST['year']));

 

 

if($_SERVER['REQUEST_METHOD']=="POST")

{

//Add a multipart boundary above the plain message   

$to = 'Del*Nique Works <[email protected]>';

$to = 'SizeSexyDivas <[email protected]>';

$from = stripslashes($fName . " " . $lName . " at " . $email);

$subject = "Contestant Application " .strftime("%T", time());

 

// generate a random string to be used as the boundary marker

$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

 

// Add the headers for a file attachment

  $head = "From: $from\n".

  "\nMIME-Version: 1.0\n" .

            "Content-Type: multipart/mixed;\n" .

            " boundary=\"{$mime_boundary}\"";

 

 

// here, we'll start the message body. this is the text that will be displayed in the e-mail

 

 

$application = "SizeSexyDiva of the Year Contestant: $from\n\n";

             

$application .= "

Name: $fName" . " " . "$lName \n

Occupation: $job \n

Location: $location \n

Phone: $phone \n

Age: $age \n

Email: $email \n

Website: $web \n

Facebook: $facebook\n

Newsletter: $news\n

Full Body: $fdata\n

Head Shot: $hdata\n

Bio: $bio \n\n ";

 

 

 

//next, we'll build the invisible portion of the message body *note that we insert two dashes in front of the MIME boundary when we use it

 

            $application = "This is a multi-part message in MIME format.\n\n" .   

                  "--{$mime_boundary}\n" .   

                    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .   

                    "Content-Transfer-Encoding: 7bit\n\n" . $application ."\n\n";

                   

                   

//now we'll process our uploaded files

foreach($_FILES as $userfile){

//store the file information to variables for easier access

$tmp_name = $userfile['tmp_name'];

$type = $userfile['type'];

$name = $userfile['name'];

$size = $userfile['size'];

 

// if the upload succeded, the file will exist

if (file_exists($tmp_name))

{

 

// check to make sure that it is an uploaded file and not a system file

if (is_uploaded_file($tmp_name))

  {

 

                //open the file for a binary read the file to be attached ('rb' = read binary)

                $file = fopen($tmp_name,'rb');

               

                // read the file content into a variable

                $data = fread($file,filesize($tmp_name));

               

                // close the file

                fclose($file);

             

            // Base64 encode the file data for full and split it into acceptable length lines

              $data = chunk_split(base64_encode($data));

                    }

 

  $application .= "--{$mime_boundary}\n" .   

                    "Content-Type: {$type};\n" .   

                    " name=\"{$name}\"\n" .   

                    "Content-Disposition: attachment;\n" .   

                    " filename=\"{$fileatt_name}\"\n" .

                    "Content-Transfer-Encoding: base64\n\n" .   

                    $data . "\n\n";

                     

                }

        }

 

// here's our closing mime boundary that indicates the last of the message

  $application .= "--{$mime_boundary}--\n";

 

                        //send mail function

                    @mail( $to, $subject, $head, $application);

?>

 

So if you can help me I would really appreciate it.

Link to comment
https://forums.phpfreaks.com/topic/212989-email-attachment-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.