Sublime directory Surf the web anonymous Pagerank Monitor


email an attachment

msthac01
Wed 5 March 2008, 05:53 pm GMT +0100
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'>
</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."";
}

olaf
Wed 5 March 2008, 07:58 pm GMT +0100
use phpmailer

msthac01
Wed 5 March 2008, 08:09 pm GMT +0100
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);

?>

olaf
Wed 5 March 2008, 09:52 pm GMT +0100
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 :D

msthac01
Thu 6 March 2008, 11:46 pm GMT +0100
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'>
</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?

olaf
Fri 7 March 2008, 07:21 am GMT +0100
check also their manual, the methods and variables are very well documented. You need to enable this setting:

$mail->IsHTML(true);

Nikolas
Sat 8 March 2008, 02:41 pm GMT +0100
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. It is another great library for mail.

olaf
Sat 8 March 2008, 03:38 pm GMT +0100
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. 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

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional