views:

119

answers:

2

I have one form (input.html) that's completed by people working in five different divisions of this business. When the form is submitted it posts to output.php.

Output.php does a number of things: First it displays all of the input information to the screen as a completed form. (Just to show them their completed document).

It has also created a file called unique_file.html based on two of the input fields in input.html.

Next, output.php has sent an email to one of five email groups, based upon another input field selected in input.html.

Finally (for now), I need the unique_file.html to be an attachment to the email. That is my problem.

I have found scripts for uploading files, I have found many tutorials about uploading files, but I just want to attach the unique_file.html to my outgoing email and I am not seeing how that is done.

Can someone point me in the right direction as to where to start? I am certainly missing the boat on this one and I have probably seen it and not realized it.

A: 

Hello,

If you can use the Zend_Framework you can easily attach file to an email i.e.

$mail = new Zend_Mail();

$at = new Zend_Mime_Part($myImage);
$at->type        = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding    = Zend_Mime::ENCODING_8BIT;
$at->filename    = 'test.gif';

$mail->addAttachment($at);

$mail->send();

see the documentation, You should be able to attach a file also by using Mail_Mime pear package and the normal mail function.

But I think the solution using the Zend framework is much more straight forward.

Cheers.

RageZ
A: 

I find PHPMailer best for this. An example from their site:

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

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

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->AddReplyTo("[email protected]","First Last");

$mail->SetFrom('[email protected]', 'First Last');

$mail->AddReplyTo("[email protected]","First Last");

$address = "[email protected]";
$mail->AddAddress($address, "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!";
}
Josh