Page 1 of 1
send attachment in body with mail
Posted: Sun Mar 15, 2009 6:01 am
by shafiq2626
helow
i want to send picture as a message through php email.
picture should be show in body.
thanks
Re: send attachment in body with mail
Posted: Sun Mar 15, 2009 9:11 am
by shafiq2626
Just Copy This Script and send picture as a message
Code: Select all
<?php
[color=#FF0000]$email= $_POST['email'];
[color=#FFBF00]//$email="abu_alkhaleeq@yahoo.com";
[color=#FFBF00] //print $email;[/color][/color]
$tmp = $_FILES['file']['tmp_name'];
$sep = md5(time());
$filename = $_FILES['file']['name'];
$filedata = file_get_contents($tmp); //Get file contents
$fdata = chunk_split(base64_encode($filedata));
//Encode data into text form
[color=#FFBF00]//Email address to send this to
//Determine mime type[/color]
$ext = explode('.', $filename);
$ext = $ext[1];
if($ext == "JPG" || $ext == "jpg" || $ext == "JPEG" || $ext == "jpeg") {
$mime_type = "image/jpeg";
}
elseif($ext == "gif" || $ext == "GIF") {
$mime_type = "image/gif";
}
else {
exit("Error: Wrong file type!");
}
[color=#FFBF00]//Begin the message. Be sure to change this how you want it.[/color]$message = "Email message here";
[color=#FFBF00]//Begin the headers[/color]
$headers = "From: \"www.dawateislami.info\" <{webdeveloper@dawateislami.info}>
MIME-Version: 1.0
Content-Type: Multipart/Mixed;
boundary=\"$sep\"
charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
--$sep
Content-Type: $mime_type;
name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=\"$filename\"
$fdata
--$sep";
$subject = "Message";
mail($email, $subject, $message, $headers);[/color]
?>
[*][*][*]
Re: send attachment in body with mail
Posted: Sun Mar 15, 2009 11:46 am
by jh_1981
Re: send attachment in body with mail
Posted: Sun Mar 15, 2009 3:10 pm
by Benjamin
Please use the appropriate
Code: Select all
[ /code] tags when posting code blocks in the forums. Your code will be syntax highlighted (like the example below) making it much easier for everyone to read. You will most likely receive more answers too!
Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces. You can even start right now by editing your existing post!
If you are new to the forums, please be sure to read:
[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]
If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online. You'll find code samples, detailed documentation, comments and more.
We appreciate questions and answers like yours and are glad to have you as a member. Thank you for contributing to phpDN!
Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]