7, September 2008

email an attachment - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: email an attachment
« previous next »
Pages: [1] Print

Author Topic: email an attachment  (Read 396 times)
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« on: Mar 05, 2008, 06:53:04 PM »

I'm trying to email a pdf attachment through php's mail function and the email comes through with the attachment intact yet the body of the email doesn't come through.  The email I'm adding this attachment to has been in use for a while just needed to upgrade it with the attachment.  Any ideas on why its not working properly here's my code so far...

<?php

$fileatt_name = 'AmendatoryClause(Letter).pdf';
$fileatt_type = 'application/pdf';
$fileatt = 'AmendatoryClause(Letter).pdf';
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
$data = chunk_split(base64_encode($data));
             
// echo $data;
 
 
$borEmail = 'mattthacker@looktoliberty.com';
            
went = mail("".$borEmail.", ".$MAEmail."", "PreApproval Letter from ".$MAName."",
"<html>
<head>
<style>
BODY
{
background-color: #FFFFFF;
}
TD
{
font-size: 10pt;
font-family: arial;
}
</style>
</head>
<table align='center' valign='top' border='5'>
<tr><td>
<table>
<tr><td>
<center>
<img height='195' width='261' src='http://www.looktoliberty.com/Enterprise/images/liberty.gif'> Visit through proxy
</center>
</td></tr>
<tr><td><center><i>(888)622-8470</center></td></tr>
<tr><td><center><i>www.LookToLiberty.com</center></td></tr>
<tr><td><hr></td></tr>
<tr>
<td>            
".$theDate."
<br><br>                  
Dear ".$borName.",
<br><br>
<b>Re:  Loan Pre-Approval Notification and Conditions</b>
<br><br>
It is with great pride and pleasure that Liberty Mortgage Funding extends to you the PreApproval of
your home loan.  From the onset of your application we have enjoyed working with you to accumulate
the necessary documentation to arrive to this momentous occasion whereby we are able to issue your
commitment, with the following terms.
<br><br>
<b>Name(s):</b><br>                  
<u>".$borName." ".$coName."</u>
<br><br>
<b>Secured by the property located at:</b><br>
".$propAddr."</u>                     
<b>Loan Terms:</b><br>
<u>Sales Price:  $".number_format($row_PurchPA['purchasePrice'], 0, '.', ',')."</u><br>
<u>Loan Amount:  $".number_format(($row_loan['loanAmount'] + $row_loan['secondLoanAmount']), 0, '.', ',')."</u><br></u>
".$sellersConc."                     
<br><br>
".$FHAVAinfo."
This PreApproval is subject to certain conditions and restrictions including a requirement that you
provide us with additional documentation to support the information already provided and that your
financial situation remains unchanged or improves.  Final approval subject to verification of
documentation submitted and information obtained from the   borrower as well as conformance   with
underwriting guidelines.  Any change in this information upon verification or change in credit
may invalidate this PreApproval.  This letter is valid for 60 days from the date the initial credit
report was obtained.
<br><br>
Once you have selected the property you wish to purchase, and before you sign a purchase agreement,
please let us know immediately the exact payments for Property Taxes, Homeowner's Insurance
and Homeowner's Association dues, and we will issue a conditional approval based on these accurate figures.
<br><br>
Liberty Mortgage Funding assumes we will be using our internal Title Company, Freedom Preferred
Title (an affiliate of First American Title) to ensure accurate and timely closings.  Freedom
Preferred Title will close your home loan at a location you or the seller chooses, wherever is
most convenient for all parties - including either Realtor's office, the Seller's Home or at a
location of your choosing.        
<br><br>            
We understand that financing your home is one of the most important decisions you make in your lifetime.
Liberty Mortgage Funding would like to make your experience as delightful as the time you will spend in
your new home.  Please feel free to call us if you have any questions on the terms and conditions of this
approval.  Thank you for your immediate attention.
<br><br>
Sincerely,
<br><br>
".$MAName."<br>
Mortgage Advisor
</td>
</tr>
</table>
</td></tr>
</table>",
"From: ".$MAEmail."\n".
"MIME-Version: 1.0\n".
"Content-type: text/html; charset=iso-8859-1".
"--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .$data. "\n\n" );
            
fclose($file);
                     
if($went)
{
   echo "You have successfully sent the PreApproval letter to:  ".$borEmail."";
}
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Mar 05, 2008, 08:58:18 PM »

use phpmailer


Last blog : Is your website is down? Know before your visitors do!
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« Reply #2 on: Mar 05, 2008, 09:09:28 PM »

well i don't want to have to add anything for our email, since we've been using php mail() for a long time and its worked pretty well for us, just this one particular email that needs a generic pdf file sent along with it.  I looked through some other examples around the net and managed to get mine to send the email and an attachment, but it won't open in adobe due to corrupt file and it doesn't give it the right name  herer's my code

<?php

$fileatt_name = 'AmendatoryClause(Letter).pdf';
$fileatt_type = 'application/pdf';
                      
$fileatt = 'AmendatoryClause(Letter).pdf';
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
$data = chunk_split(base64_encode($data));
// echo $data;
               
$num = md5(time());
//echo $num;
   
//Normal headers

$headers  = "From:".$MAEmail."\r\n";
$headers  .= "MIME-Version: 1.0\r\n";
$headers  .= "Content-Type: multipart/mixed; ";
$headers  .= "boundary=".$num."\r\n";
$headers  .= "--".$num."\r\n";

// This two steps to help avoid spam   

//       $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['Server'].">\r\n";
//       $headers .= "X-Mailer: PHP v".phpversion()."\r\n";         

// With message
       
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n"; 

// Attachment headers

$headers  .= "Content-Type: application/pdf; \n";
$headers  .= "name=\" .$fileatt_name. \"\r\n";
$headers  .= "Content-Transfer-Encoding: base64\r\n";
$headers  .= "Content-Disposition: attachment; ";
$headers  .= "filename= \"".basename($fileatt_name)."\"\r\n\n";
$headers  .= "".$data."\r\n";
$headers  .= "--".$num."--";
// SEND MAIL
         
$to = $borEmail.", ".$MAEmail;
         
$theTest = mail($to, $subject, $message, $headers);

?>
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Mar 05, 2008, 10:52:03 PM »

Believe me sending valid mime mail is a pain in the ___s

I wrote a class by myself and today I'm using phpmailer, sure you can play with your script a few days more and move than to phpmailer Cheesy


Last blog : Is your website is down? Know before your visitors do!
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« Reply #4 on: Mar 07, 2008, 12:46:45 AM »

Well I took your advice and am trying to use phpmailer, my first attempt got the email to send and the attachment went through fine...but my email body is html and it just showed up as the html text instead of formatting it accordingly.

Here's my code

<?php

$message = "<html><head><style>BODY{ background-color: #FFFFFF;}
    TD {font-size: 10pt; font-family: arial; }</style></head>
   <table align='center' valign='top' border='5'>
      <tr><td>
   <table>
   <tr><td>
   <center>
   <img height='195' width='261' src='http://www.looktoliberty.com/Enterprise/images/liberty.gif'> Visit through proxy
   </center>
   </td></tr>
   <tr><td><center><i>(888)622-8470</center></td></tr>
     <tr><td><center><i>www.LookToLiberty.com</center></td></tr>
   <tr><td><hr></td></tr>
   <tr>
   <td>            
   ".$theDate."
   <br><br>                  
   Dear ".$borName.",
   <br><br>
   <b>Re:  Loan Pre-Approval Notification and Conditions</b>
   <br><br>
   It is with great pride and pleasure that Liberty Mortgage Funding extends to you the PreApproval of
   your home loan.  From the onset of your application we have enjoyed working with you to accumulate
   the necessary documentation to arrive to this momentous occasion whereby we are able to issue your
   commitment, with the following terms.
   <br><br>
   <b>Name(s):</b><br>                  
   <u>".$borName." ".$coName."</u>
   <br><br>
   <b>Secured by the property located at:</b><br>
   ".$propAddr."</u>                     
   <b>Loan Terms:</b><br>
   <u>Sales Price:  $".number_format($row_PurchPA['purchasePrice'], 0, '.', ',')."</u><br>
   <u>Loan Amount:  $".number_format(($row_loan['loanAmount'] + $row_loan['secondLoanAmount']), 0, '.', ',')."</u><br></u>
   ".$sellersConc."                     
   <br><br>
   ".$FHAVAinfo."
   This PreApproval is subject to certain conditions and restrictions including a requirement that you
   provide us with additional documentation to support the information already provided and that your
   financial situation remains unchanged or improves.  Final approval subject to verification of
   documentation submitted and information obtained from the borrower as well as conformance with
   underwriting guidelines.  Any change in this information upon verification or change in credit
   may invalidate this PreApproval.  This letter is valid for 60 days from the date the initial credit
   report was obtained.
   <br><br>
   Once you have selected the property you wish to purchase, and before you sign a purchase agreement,
   please let us know immediately the exact payments for Property Taxes, Homeowner's Insurance
   and Homeowner's Association dues, and we will issue a conditional approval based on these accurate figures.
   <br><br>
   Liberty Mortgage Funding assumes we will be using our internal Title Company, Freedom Preferred
   Title (an affiliate of First American Title) to ensure accurate and timely closings.  Freedom
   Preferred Title will close your home loan at a location you or the seller chooses, wherever is
   most convenient for all parties - including either Realtor's office, the Seller's Home or at a
   location of your choosing.        
   <br><br>            
   We understand that financing your home is one of the most important decisions you make in your lifetime.
   Liberty Mortgage Funding would like to make your experience as delightful as the time you will spend in
   your new home.  Please feel free to call us if you have any questions on the terms and conditions of this
   approval.  Thank you for your immediate attention.
   <br><br>
   Sincerely,
   <br><br>
   ".$MAName."<br>
   Mortgage Advisor
   </td>
   </tr>
   </table>
   </td></tr>
   </table>
   </html>";
                     
   $fileatt_name = 'AmendatoryClause(Letter).pdf';
   $fileatt_type = 'application/pdf;';
                     
   $mail = new PHPMailer();

   $mail->From     = $MAEmail;
   $mail->FromName = $MAName;
   $mail->Host     = "smtp.looktoliberty.com";
   $mail->Mailer   = "smtp";


       // HTML body
       $body  = $message;
       $mail->Body    = $body;
       $mail->AddAddress($borEmail, $MAEmail);
       $mail->AddAttachment("AmendatoryClause(Letter).pdf", "AmendatoryClause(Letter).pdf");  // optional name
     if(!$mail->Send())
                {
    echo "There has been a mail error sending to " . $borEmail.", ".$MAEmail . "<br>";
   }
   else
   {
    echo 'It Sent';
   }

Any ideas on why the html is coming through as plain text, at least thats what it looks like?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Mar 07, 2008, 08:21:25 AM »

check also their manual, the methods and variables are very well documented. You need to enable this setting:

   $mail->IsHTML(true);


Last blog : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #6 on: Mar 08, 2008, 03:41:15 PM »

Yeah Olaf's example works. If you still have problems with phpMailer (I had a few problems with utf-8 encoded messages) try swift mail Visit through proxy. It is another great library for mail.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Mar 08, 2008, 04:38:32 PM »

Yeah Olaf's example works. If you still have problems with phpMailer (I had a few problems with utf-8 encoded messages) try swift mail Visit through proxy. It is another great library for mail.

yeah right both of them are the best php mail scripts around here, most bigger projects are using them


Last blog : Is your website is down? Know before your visitors do!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7631
Tags : php email attachments Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: email an attachment
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 07, 2008, 11:00:53 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.301
Total Topics: 7.479
Total Members: 3.904
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: Brandon

22 Guests, 3 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.