Email image attachment with php
| From: | Absm | Date: | Wed, 16 Feb 2000 00:41:16 +0000 |
| Subject: | Email image attachment with php | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-10325@lists.php.net to get a copy of this message | ||
Could somene please help with the following:
Below is part of a submission form that deals with images.
Upto 3 Images May Be Sent.<br><p></p>
photo1<input type="file" name="picture" size="25"><br>
photo2<input type="file" name="picture" size="25"><br>
photo3<input type="file" name="picture" size="25"><br>
****************************************************************************
******************
This bit of code deals with the email notification of text entered from the
form that handles text input not shown above.
How can physical images like "jpg" be attached and sent together with the
text notification ???
mail("$email_address", "Your Profile setup",
"$first_name Thank you for your interest!
Your Profile Has Been Successfully Entered Onto This Website
We Hope You Enjoy Every Visit!!!
sve.com")
; mail("enquiry@sve.com","New Customer Profile",
"Ref No:$ref, First name:$first_name, Last name:$last_name, Post
address:$post_address ,Phone No:$phone_no , Email:$email_address");
****************************************************************************
********************
This bit of code i understand is able to attach and send images.
Alternatively,
Tryed using the above bit of the html code to select images and setting this
script with appropriate variables
However having trouble making it work.
Any corrections that could be pointed ????
<?
// ************************************
// E-mail functions (binary attachment)
// ************************************
$dest_email="enquiry@sve.com";
$title="Mail Attach";
$message_to_send="Testing Mail Attachment"
$from="$email_address";
$type="jpg";
$filename="$picture_name";
$path="$picture_path";
$type="$picture_type";
m_attach_bin($dest_email, $title, $message_to_send, $from, $type);
m_attach_file_bin($filename, $path, $type);
m_attach_send_bin($type);
function m_attach_bin( $to_fname, $subject_ftext, $message, $from, $type )
{
static $hold_to="";
static $hold_subject="";
static $hold_from="";
static $hold_message="";
static $boundary="-----------------kjbsdf9873987348735";
static $MIME="MIME-Version: 1.0\nContent-Type:
multipart/mixed;\n\tboundary=\"$boundary\"\n\nThis is a multi-part message
in MIME format.\n\n";
static $startMsg="\n--$boundary\nContent-Type:
text/plain;\n\tcharset=\"iso-8859-1\"\nContent-Transfer-Encoding: 8bit\n\n";
static $ending="\n--$boundary--";
if ( $to_fname=="" ) /* send it! */
{
$hold_message=$hold_message . $ending;
return( mail( $hold_to, $hold_subject, $hold_message, $hold_from ) );
}
elseif ( $message=="" ) /* we must be attaching a file */
$hold_message=$hold_message . "\n--$boundary\nContent-Type:
image/".$type.";\n\tname=\"$to_fname\"\nContent-Transfer-Encoding:
base64\nContent-Disposition:
inline;\n\tfilename=\"$to_fname\"\n\n$subject_ftext";
}
else /* starting a new message */
{
$hold_to=$to_fname;
$hold_subject=$subject_ftext;
$hold_message=$startMsg . $message."\n\n";
$hold_from="From: $from\n$MIME\n";
}
};
function m_attach_file_bin( $shortname, $longname, $type )
{
$fp=fopen($longname,"r");
$in = fread( $fp, filesize( $longname ) );
fclose( $fp );
$out= chunk_split(base64_encode($in));
return( m_attach_bin( $shortname, $out, "", "", $type ) );
};
function m_attach_send_bin($type)
{
return( m_attach_bin( "","","","", $type ) );
};
*/
// *************** End E-mail functions *****************
/*
USAGE:
Set the following variables as appropriate:
$dest_email: the destination address
$title: message subject
$message_to-send: the message you want to send
$from: your e-mail address
$type: file type (i.e. "jpg", "gif" ect)
$fillename: the complete filename
$path the complete path to your file (including the file name)
Then simply call the following functions:
m_attach_bin($dest_email, $title, $message_to_send, $from, $type);
m_attach_file_bin($filename, $path, $type);
m_attach_send_bin($type);
I tested the function with jpg and gif only but some friends reported me
they work with every kind of file.
*/
abbs1@x-stream.co.uk
thanks