0
$content = chunk_split(base64_encode(file_get_contents('test.dpa')));
$uid = md5(uniqid(time()));

$header = "From: mail@mail.com\r\nReply-To: mail@mail.com\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $msg."\r\n\r\n";

$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"test.dpa\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"test.dpa\"\r\n\r\n";
$header .= $content."\r\n\r\n";

if( mail($_POST['email'], 'TESTING MAIL', "", $header ) )
    echo "SUCCESS !";
else
    echo "NOPE !";

I want to send a mail with attachment. I'm formatting the $msg from a completed form. - test.dpa - is a file.

My problem is with the statement. Why the statement is FALSE ? I'm getting the "NOPE" result if I want to send the mail. But why? Where is the problem? I don't get it.

Reteras Remus
  • 923
  • 5
  • 19
  • 34
  • 1
    `mail()` returning false means there was a problem handing the email off to your local SMTP server. mail() by itself couldn't care less what the mail's content is. Beyond that, don't build your own mime emails. use PHPMailer or Swiftmailer. They'll reduce that entire chunk of `$header` stuff down about 3 lines of code. – Marc B Jul 12 '12 at 18:34
  • Are you sure that your $_POST['email'] is correct? If I replace it with an valid email address, I will get "SUCCESS" – Talisin Jul 12 '12 at 18:37
  • 1
    Maybe you forgot to set up your SMTP server? – Darvex Jul 12 '12 at 18:38
  • Also I think that the line `This is a multi-part message in MIME format` and everything after it should be part of the `$message` rather than the headers. – drew010 Jul 12 '12 at 18:59

0 Answers0