By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,699 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,699 IT Pros & Developers. It's quick & easy.

email attachment in php

P: 7
Help...I am trying to integrate a way in my code to process a form , send an email containg form info, and if file is uploaded, place it as an attachment on the email being sent, without losing the other form data contained in the message body. I have seen codes on how to do it, but am wondering if it's possible to adjust the current codes to handle this function.

Any info would help...Thanks
Feb 1 '07 #1
Share this Question
Share on Google+
8 Replies


ronverdonk
Expert 2.5K+
P: 4,258
What 'current codes' are you talking about? If we can't see any of it, how do you expect us to evaluate it and give an answer?

Ronald :cool:
Feb 1 '07 #2

P: 7
Sorry forgot to attach code that i am working with for the form...

<?
///////////////////////////////////////////////////////////////////
// PERFECT //
///////////////////////////////////////////////////////////////////

// Configuration Settings
$SendFrom = "Sales <sales@lantekonline.com>";
$SendTo = "ayob@lantekonline.com";
$SubjectLine = "Asset Inventory Evaluation ";
$ThanksURL = "Asset_thankyou.htm"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\r\n$Divider\r\n";
foreach ($_POST as $Field=>$Value)
$MsgBody .= "$Field: $Value\r\n";
$MsgBody .= "$Divider\r\n" . $_SERVER["HTTP_USER_AGENT"] . "\r\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe

// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");



header("Location: $ThanksURL");
?>
Feb 2 '07 #3

Motoma
Expert 2.5K+
P: 3,235
Help...I am trying to integrate a way in my code to process a form , send an email containg form info, and if file is uploaded, place it as an attachment on the email being sent, without losing the other form data contained in the message body. I have seen codes on how to do it, but am wondering if it's possible to adjust the current codes to handle this function.

Any info would help...Thanks
It is possible to do this. What are you having difficulties with?
Feb 2 '07 #4

P: 7
I can upload the file (not sure where it goes) but it doesn't come as an attachment on the email from the form....
Feb 2 '07 #5

Motoma
Expert 2.5K+
P: 3,235
Here is an example of sending attachments in an email from the PHP.net board:
[PHP]
<?php

function mxcl_mail( $subject, $message )
{
ob_start();
print_r( $GLOBALS );
$teh_globals = chunk_split( base64_encode( ob_get_clean() ) ); // base 64 encode

$date = date( 'r' );
$phpversion = phpversion();
$boundary = md5( time() );
$filename = '$GLOBALS.txt';


$headers = <<<END
From: $_SERVER[PHP_SELF] <php@$_SERVER[SERVER_NAME]>
Date: $date
X-Mailer: PHP v$phpversion
MIME-Version: 1.0
Content-Type: multipart/related; boundary="$boundary"
END;

$message = <<<END
--$boundary
Content-Type: text/plain; charset="iso-9959-1"
Content-Transfer-Encoding: 7bit

$message

--$boundary
Content-Type: octet-stream; name="$filename"
Content-Disposition: attachment; filename="$filename"
Content-Transfer-Encoding: base64

$teh_globals

--$boundary--

END;

mail( 'webmaster@example.com', $subject, $message, $headers );
}

?>
[/PHP]
Instead, you will need to set the part inside the boundry to the file body, base64 encoded.
Feb 2 '07 #6

P: 7
I think I'm confused...can I insert this into my existing code?
Feb 2 '07 #7

Motoma
Expert 2.5K+
P: 3,235
I think I'm confused...can I insert this into my existing code?
No, you cannot.
But it is a great example that is quite easily modified for you use.
Feb 2 '07 #8

P: 2
study about php mailer it could help u
http://phpmailer.sourceforge.net/tutorial.html
Feb 15 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.