PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 11th, 2012, 03:48 PM
atrhick atrhick is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 atrhick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 40 sec
Reputation Power: 0
Multipart Email. not sending mail

Hey guys,

I cant seem to find any errors in my code. what i am trying to do is send an email with an attachment. please have a look at my code and tell me know what you think.


PHP Code:
<?php
    $cname                 
$_POST['cname'];
    
$caddress1             $_POST['caddress1'];
    
$curl                 $_POST['curl'];
    
$caddress2             $_POST['caddress2'];
    
$cphone             $_POST['cphone'];
    
$cphoneext             $_POST['cphoneext'];
    
$ccity                 $_POST['ccity'];
    
$cstate             $_POST['pwphone'];
    
$cstate             $_POST['cstate'];
    
$mphone             $_POST['mphone'];
    
$czip                 $_POST['czip'];
    
$fax                 $_POST['fax'];
    
$fname                 $_POST['fname'];
    
$lname                 $_POST['lname'];
    
$namemi             $_POST['namemi'];
    
$email                 $_POST['email'];
    
$cbsb                 $_POST['cbsb'];
    
$cbna                 $_POST['cbna'];
    
$plicense             $_POST['plicense'];
    
$plstate             $_POST['plstate'];
    
$plnum                 $_POST['plnum'];
    
$plexpdate             $_POST['plexpdate'];
    
$plyexp             $_POST['plyexp'];
    
$slicense             $_POST['slicense'];
    
$slstate             $_POST['slstate'];
    
$slnum                 $_POST['slnum'];
    
$slexpdate             $_POST['slexpdate'];
    
$slyexp             $_POST['slyexp'];
    
$specials            $_POST['specials'];
    
$comments             $_POST['comments'];
    
$zipcodes             $_POST['zipcodes'];
    
$counties             $_POST['counties'];
    
$milesfromoffice     $_POST['milesfromoffice'];
    
$cbrpm                 $_POST['cbrpm'];
    
$cbres                 $_POST['cbres'];
    
$cbss                 $_POST['cbss'];
    
$cbrl                 $_POST['cbrl'];
    
$cbec                 $_POST['cbec'];
    
$cbloc                 $_POST['cbloc'];
    
$cbrack             $_POST['cbrack'];
    
$cbinsp             $_POST['cbinsp'];
    
$cbpps                 $_POST['cbpps'];
    
$cbpcr                 $_POST['cbpcr'];
    
$cbbpo                 $_POST['cbbpo'];
    
$cboc                 $_POST['cboc'];
    
$cbsrs                 $_POST['cbsrs'];
    
$cblm                 $_POST['cblm'];
    
$cbvara             $_POST['cbvara'];
    
$cbcust1             $_POST['cbcust1'];
    
$tbcust1             $_POST['tbcust1'];
    
$cbcust2             $_POST['cbcust2'];
    
$tbcust2             $_POST['tbcust2'];
    
$cbcust3             $_POST['cbcust3'];
    
$tbcust3             $_POST['tbcust3'];
    
$cbcust4             $_POST['cbcust4'];
    
$tbcust4             $_POST['tbcust4'];
    
$cbcust5             $_POST['cbcust5'];
    
$tbcust5             $_POST['tbcust5'];
    
$cbcust6             $_POST['cbcust6'];
    
$tbcust6             $_POST['tbcust6'];
    
$cbcust7             $_POST['cbcust7'];
    
$tbcust7             $_POST['tbcust7'];
    
$cbcust8             $_POST['cbcust8'];
    
$tbcust8             $_POST['tbcust8'];
    
$heard                 $_POST['heard'];
    
$numprops             $_POST['numprops'];
    
    
$htmlbody "Company Name: ".$cname."<br/>";
    
$htmlbody .= "Company Address 1: ".$caddress1."<br/>";
    
$htmlbody .= "Company Address 2: ".$caddress2."<br/>";
    
$htmlbody .= "Company URL: ".$curl."<br/>";
    
$htmlbody .= "Company Phone: ".$cphone."<br/>";
    
$htmlbody .= "Company Phone Ext: ".$cphoneext."<br/>";
    
$htmlbody .= "Company City: ".$ccity."<br/>";
    
$htmlbody .= "Company State: ".$cstate."<br/>";
    
$htmlbody .= "Company Work Phone: ".$pwphone."<br/>";
    
$htmlbody .= "Company Mobile Phone: ".$mphone."<br/>";
    
$htmlbody .= "Company Zip: ".$czip."<br/>";
    
$htmlbody .= "Company Fax: ".$fax."<br/>";
    
$htmlbody .= "First Name: ".$fname."<br/>";
    
$htmlbody .= "Last Name: ".$lname."<br/>";
    
$htmlbody .= "Middle Initial: ".$namemi."<br/>";
    
$htmlbody .= "Email: ".$email."<br/>";
    
$htmlbody .= "Sponsoring Broker: ".$cbsb."<br/>";
    
$htmlbody .= "Agent needing Broker Approval: ".$cbna."<br/>";
    
$htmlbody .= "License type - Primary: ".$plicense."<br/>";
    
$htmlbody .= "State of Issuance: ".$plstate."<br/>";
    
$htmlbody .= "License Number: ".$plnum."<br/>";
    
$htmlbody .= "Expiration Date: ".$plexpdate."<br/>";
    
$htmlbody .= "Years of Experience: ".$plyexp."<br/>";
    
$htmlbody .= "License type - Secondary: ".$slicense."<br/>";
    
$htmlbody .= "State of Issuance: ".$slstate."<br/>";
    
$htmlbody .= "License Number: ".$slnum ."<br/>";
    
$htmlbody .= "Expiration Date: ".$slexpdate ."<br/>";
    
$htmlbody .= "Years of Experience: ".$slyexp ."<br/>";
    
$htmlbody .= "Professional Designations and Specializations: ".$specials."<br/>";
    
$htmlbody .= "Comments Regarding Services: ".$comments ."<br/>";
    
$htmlbody .= "Zip Codes: ".$zipcodes ."<br/>";
    
$htmlbody .= "Counties: ".$counties ."<br/>";
    
$htmlbody .= "Miles from Office: ".$milesfromoffice ."<br/>";
    
$htmlbody .= "Residential Property Management: ".$cbrpm ."<br/>";
    
$htmlbody .= "Real Estate Sales: ".$cbres ."<br/>";
    
$htmlbody .= "Short Sales: ".$cbss ."<br/>";
    
$htmlbody .= "Residential Leasing: ".$cbrl ."<br/>";
    
$htmlbody .= "Eviction Coordination: ".$cbec ."<br/>";
    
$htmlbody .= "Lock-Out Coordination: ".$cbloc ."<br/>";
    
$htmlbody .= "Relocation Assistance -- Cash for Keys: ".$cbrack ."<br/>";
    
$htmlbody .= "Property/Occupancy Inspections: ".$cbinsp ."<br/>";
    
$htmlbody .= "Property Preservation Services: ".$cbpps ."<br/>";
    
$htmlbody .= "Property Condition Reports: ".$cbpcr ."<br/>";
    
$htmlbody .= "Broker Price Opinion (BPO) and Appraisal Coordination: ".$cbbpo ."<br/>";
    
$htmlbody .= "Occupancy Checks: ".$cboc ."<br/>";
    
$htmlbody .= "Securing and Rekeying Services: ".$cbsrs ."<br/>";
    
$htmlbody .= "Loss Mitigation: ".$cblm ."<br/>";
    
$htmlbody .= "Value Added Repair Analysis: ".$cbvara ."<br/>";
    
$htmlbody .= "Other : ".$cbcust1 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust1  ."<br/>";
    
$htmlbody .= "Other : ".$cbcust2 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust2 ."<br/>";
    
$htmlbody .= "Other : ".$cbcust3 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust3 ."<br/>";
    
$htmlbody .= "Other : ".$cbcust4 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust4 ."<br/>";
    
$htmlbody .= "Other : ".$cbcust5 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust5 ."<br/>";
    
$htmlbody .= "Other : ".$cbcust6 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust6 ."<br/>";
    
$htmlbody .= "Other : ".$cbcust7 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust7 ."<br/>";
    
$htmlbody .= "Other : ".$cbcust8 ."<br/>";
    
$htmlbody .= "Other : ".$tbcust8 ."<br/>";
    
$htmlbody .= "Other : ".$heard ."<br/>";
    
$htmlbody .= "Other : ".$numprops ."<br/>";
    
    
    
//Set Recipient Address
    
$to "email@hotmail.com";
    
//Set Recipient Address
    
$from "email@rmsnav.com";
    
//Set Email Subject
    
$subject "HTML email with attachment";
    
    
    
    
//read the atachment file contents into a string,
    //encode it with MIME base64,
    //and split it into smaller chunks for sending
    
    
if(!empty($numprops)){
    
        
$file_name $_FILES['w9file ']['name'];
        
$temp_name $_FILES['w9file ']['temp_name'];
        
$file_type $_FILES['w9file ']['type'];
        
        
//get the extenstion of the file
        
$base basename($file_name);
        
$extension substr($basestrlen($base)-4strlen($base));
        
        
// only these files types will be allowed
        
$allowed_extensions = array(".doc","docx",".pdf",".zip",".png",".xls",".jpg",".jpeg");
        
        
//this is just for namesing
        
$file $file_name;
        
$contents chunk_split(base64_encode(file_get_contents($file)));
        
$uid md5(uniqid(time()));
        
        
//define the from reply to headers
        
$headers "From: ".$from."\r\n";
        
$headers .= "Reply-To: ".$to."\r\n";
        
$headers .= "MIME-Version: 1.0\r\n";
        
        
//define the body of the message.
        
$headers .="Content-Type: multipart/alternative; boundary=\"".$uid."\"r\n\r\n";
        
$headers .= "This is a multi-part message in MIME format. \r\n";
        
$headers .= "Content-type:text/plain; charset=iso-8859-1\r\n";
        
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        
$headers .= $htmlbody."\"r\n\r\n";
        
        
//file attachment
        
$headers .= "--".$uid."\r\n";
        
$headers .= "Content-Type: ".$file_type."; name=\"".$file_name."\"r\n\r\n";
        
$headers .= "Content-Transfer-Encoding: base64\r\n";
        
$headers .= "Content-Disposition: attachment; filename=\"".$file_name."\"r\n\r\n";
        
$headers .= $content."\"r\n\r\n";
        
        
        
        
//send the email
        
if(mail$to$subject ,""$headers));
         {
            echo 
"Mail sent!".$headers;
        }
        
    }
    
    else{
        echo 
"Mail not sent!";
        }
?>

Reply With Quote
  #2  
Old December 11th, 2012, 04:28 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 23 m 36 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
1. The [name] is just the name of the file as it was on the user's computer. It is not where the file is actually located (temporarily) on the server.
2. The [tmp_name], which is where the file is located, only has one "e" in it.
3. You have some funky \"r\n\r\n things in there.
4. The headers to mail() are the headers to the overall message. The message content is where you put the HTML and the multipart stuff.

5. Since you aren't fully aware of how the whole thing works, don't roll your own solution: go with something like PHPMailer instead.

Last edited by ManiacDan : December 12th, 2012 at 08:40 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Multipart Email. not sending mail

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap