send attachment in body with mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

send attachment in body with mail

Post by shafiq2626 »

helow
i want to send picture as a message through php email.
picture should be show in body.
thanks
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: send attachment in body with mail

Post by shafiq2626 »

Just Copy This Script and send picture as a message

Code: Select all

 
 

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]
 
?>
[*][*][*]
Last edited by shafiq2626 on Wed Mar 18, 2009 12:28 am, edited 6 times in total.
jh_1981
Forum Newbie
Posts: 22
Joined: Fri Jan 30, 2009 6:21 pm

Re: send attachment in body with mail

Post by jh_1981 »

User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: send attachment in body with mail

Post 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]
Post Reply