0

I am using this code to email:

$email="abc@gmail.com";
$to = $email;
$subject = "Test mail";
$message1 = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head></head>
  <body>
    <div  style="width:80%;">
      <table style="margin: 10px 20px 10px 20px;">
        <tr><td>Hello!'."  ".'</td></tr>';
        $message1.=$mailmessage;
        $message1.=
          '<tr><td>Please find attachments for dailyreport.</td></tr>
<tr><td><br>' . "Thanks and Regards with ". '</td></tr>
    </table></div>
  </body>
</html>';
$from = "admin@feed.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";  
if(mail($to,$subject,$message1,$headers)) {
  "mail sent";
} else {
  "email does not exist";
}

To send attachments I need to change the content type to Content-Type: multipart/mixed;\n. But the HTML context will change. How can I attach a file to this html?

dda
  • 6,030
  • 2
  • 25
  • 34
jaya
  • 327
  • 3
  • 4
  • 16

3 Answers3

1

If you want to write your own script, checkout this link

But I strongly recommend you to use custom library such as PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/

PHPMailer is a PHP email transport class featuring file attachments, SMTP servers, CCs, BCCs, HTML messages, word wrap, and more. Sends email via sendmail, PHP mail(), QMail, or directly with SMTP. Support for additional transports, such as SMS, MMS will be forthcoming

rajukoyilandy
  • 5,341
  • 2
  • 20
  • 31
0

You should try this code for header information

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\""; 
Daxen
  • 508
  • 4
  • 18
0

You have some special headers for email attachment, Don't worry we have a php class called sendMail, download and learn @ PHP sendMail class

Srihari Goud
  • 824
  • 10
  • 25