0

Possible Duplicate:
Send email with attachments in PHP?

How can I send an email attachment using PHP without installing any thing and just using the mail() function?

Community
  • 1
  • 1
HELP
  • 14,237
  • 22
  • 66
  • 100
  • There are a lot of questions answering that already, [like this one](http://stackoverflow.com/questions/1214646/send-email-with-attachments-in-php). Please do not post duplicate questions. – netcoder Dec 18 '10 at 21:45
  • @netcoder, I don't want to PHPMailer orr anything similar – HELP Dec 18 '10 at 21:47
  • Keep reading, and or use the search. There are dozens of questions providing multiple alternatives already. Posting duplicate questions is against SO rules, your question will probably be closed anyway. If you don't want PHPMailer, or Zend_Mail, or this, or that, at least specify it in the question. – netcoder Dec 18 '10 at 21:49
  • @netcoder, I thought I did no need to get mad about it. – HELP Dec 18 '10 at 21:51
  • This seems like a pretty good answer: http://stackoverflow.com/questions/1330626/how-can-i-send-an-email-with-attachments-from-a-php-form/1330629#1330629 – Rebecca Scott Dec 18 '10 at 22:14

5 Answers5

0

The zend framework has a nice class to do this. It would require that you copy the framework to your server to access it.

http://framework.zend.com/

Jason
  • 2,687
  • 3
  • 29
  • 40
0

PHPMailer can use the native mail() function:

<?php

require_once('PHPMailer_v5.1/class.phpmailer.php');

$mail = new PHPMailer(); // defaults to using php "mail()"

$body = file_get_contents('contents.html');
$mail->SetFrom($fromAddress, 'First Last');
$mail->AddReplyTo($replyToAddress, "First Last");
$mail->AddAddress($toAddress, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);

// $mail->AddAttachment("images/phpmailer.gif");      // attachment
// $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if (!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
István Ujj-Mészáros
  • 3,228
  • 1
  • 27
  • 46
0
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));

Read This Article for more information.

Brad
  • 127
  • 2
  • 10
0

Need to use a multiplart/mixed MIME type and also base64_encode the attachment.

Check this link Mail() Email Attachment for details.

csi
  • 9,018
  • 8
  • 61
  • 81
0

The attachments are included in the body of the message. It is probably a good idea to be familiar with MIME and the MIME RFCs. The link that Christopher Ickes and Brad gave will help with the implementation but the code glosses over the details that can help when debugging down the track.

Community
  • 1
  • 1
Rebecca Scott
  • 2,421
  • 2
  • 25
  • 39