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
heals1ic
Forum Newbie
Posts: 1 Joined: Tue May 15, 2007 12:11 pm
Post
by heals1ic » Tue May 15, 2007 12:23 pm
Does anyone know of a way to attach jpg image created in php without having to save the file to the server before attaching it?
I am using this MIME code to attach the image to an email -
Code: Select all
for($i=0;$i<$max;$i++)
{
$file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
$this->header .= "--".$this->boundary."\n";
$this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n";
$this->header .= "Content-Transfer-Encoding: base64\n";
$this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\n\n";
$this->header .= chunk_split(base64_encode($file))."\n";
$file = "";
}
Can I attach the image stored as a variable for instance?
stereofrog
Forum Contributor
Posts: 386 Joined: Mon Dec 04, 2006 6:10 am
Post
by stereofrog » Tue May 15, 2007 12:44 pm
For example
Code: Select all
ob_start();
imagejpeg($image_resource, '', 70);
$image_data = ob_get_clean();
$header .= chunk_split(base64_encode($image_data));
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Tue May 15, 2007 1:34 pm
Use Swiftmailer. It has a feature like that built in to it and works like a charm.