title: send email with pdf attachment
body: <p>I'm trying to send an email using the <code>mail()</code> function in php with a pdf attachment.
  I'm running the script on localmachine. I set up the smtp ip in <code>php.ini</code>.
  I can send a text email perfectly but with an attachment I get the following error:</p>
  
  <p><code>Warning: mail() [function.mail]: SMTP server response: 503 Unexpected command or sequence of commands in C:\AppServ\www\PhpProject1\CV-Generator\testemail2.php on line 55</code></p>
  
  <p>Can anyone tell me what's wrong please?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  // download fpdf class (http://fpdf.org)
  require('./pdf/fpdf.php');
  
  // fpdf object
  $pdf = new FPDF();
  
  // generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/)
  $pdf-&gt;AddPage();
  $pdf-&gt;SetFont("Arial","B",14);
  $pdf-&gt;Cell(40,10, "this is a pdf example");
  
  // email stuff (change data below)
  $to = $_GET['send']; 
  $from = "info@asaltechd.com"; 
  $subject = "send email with pdf attachment"; 
  $message = "&lt;p&gt;Please see the attachment.&lt;/p&gt;";
  
  // a random hash will be necessary to send mixed content
  $separator = md5(time());
  
  // carriage return type (we use a PHP end of line constant)
  $eol = PHP_EOL;
  
  // attachment name
  $filename = "example.pdf";
  
  // encode data (puts attachment in proper format)
  $pdfdoc = $pdf-&gt;Output("", "S");
  $attachment = chunk_split(base64_encode($pdfdoc));
  
  
  // main header (multipart mandatory)
  $headers  = "From: ".$from.$eol;
  $headers .= "MIME-Version: 1.0".$eol; 
  $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
  $headers .= "Content-Transfer-Encoding: 7bit".$eol;
  $headers .= "This is a MIME encoded message.".$eol.$eol;
  
  // message
  $headers .= "--".$separator.$eol;
  $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
  $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
  $headers .= $message.$eol.$eol;
  
  // attachment
  $headers .= "--".$separator.$eol;
  $headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
  $headers .= "Content-Transfer-Encoding: base64".$eol;
  $headers .= "Content-Disposition: attachment".$eol.$eol;
  $headers .= $attachment.$eol.$eol;
  $headers .= "--".$separator."--";
  
  // send message
  mail($to, $subject, "", $headers);
  
  ?&gt;
  </code></pre>