Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 22nd, 2005, 01:05 PM
Authorized User
 
Join Date: Jun 2005
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default embed image in php html email

I have been using php to send html emails recently and using linked images instde them. I have one occurance where I need to actually embed an image inside the email (not an attachment...it needs to show on the page) instead of using the linked images. I cannot find anything simple enough to answer my question on the internet so far. Everything out there is either an incomplete code snippet or a huge mime class. I simply need the most extremely simple example of entire php code (start to finish with no include files such as the mime classes that are floating around out there)for completing this task. If anyone can help that would be great.
Cullan
ccrothers@integrity.com
__________________
Cullan crothers
 
Old June 24th, 2005, 03:49 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

I did that easily by using PHP PEAR:
MAIL and MIME packages.

 
Old June 24th, 2005, 08:08 AM
Authorized User
 
Join Date: Jun 2005
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Yes, but using just the standard php mail() function with no mime classes, includes, or pear is what I am looking for as an example. Just one file in php that will do it using the standard php mail() funtion.

Cullan Crothers
 
Old June 24th, 2005, 08:20 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well Mail_Mime *does* use the mail function, well actually it supports several mailing methods. And it works. MIME mail is a complicated beast. I've spent loads and loads of time developing a c-client package that reads MIME mail. If you're looking for the simplest, easiest method, it would be to use one of those "huge" classes. That's why they exist in the first place, so that no one has to go to all the trouble of figuring out how MIME works.

But, if you're that determined to create your own MIME mailer. I'd download Mail_Mime and see how it generates HTML mailers with embedded images, then write a program that does the same thing. Work backwards from the MIME source. If you want more detailed examples than the PEAR version supplies, go to the original author's website at http://www.phpguru.org and get his version, which includes loads of examples. If that doesn't suit you then find the original MIME RFCs that detail how a MIME implementation should function.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old June 24th, 2005, 08:45 AM
Authorized User
 
Join Date: Jun 2005
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thank You.
 
Old June 25th, 2005, 04:54 PM
Authorized User
 
Join Date: Jun 2005
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

I finally did it and got it to work. I scrapped all the mime mail classes, did not use pear, and simply used the standard mail( ) php function to generate the php html email with an embedded image. I had to go back and start from scratch. I sent myself an email generated by MS outlook express with an embedded image in it and viewed the source from it and that told me what I was missing. After that it was just some time getting the carriage return/newlines and the boundaries to line up correctly. It tested great when recieved in both Outlook and Outlook Express. Thanks for all the suggestions.

Cullan Crothers
 
Old July 28th, 2005, 07:37 AM
Registered User
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to archanaunni
Default

Dear cullancrothers

Could you please give me the idea about using mail finction for html mails...

waiting
Krishna


embrase all
 
Old August 7th, 2005, 07:19 PM
Registered User
 
Join Date: Aug 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Cullan,

If you're willing to share what you've developed, or even some tips, I'd really appreciate it. I've only been skimming the web on this topic for awhile now, and am about to start giving it a try. Regular mail - no problem! Sending HTML email - never done it! Trying to develop a form for my client to fill out on a web page to generate the HTML email - yipes! :D

Thanks,

Jeph


 
Old August 8th, 2005, 08:17 AM
Authorized User
 
Join Date: Jun 2005
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Jeph:

PHP mail() function with html can be easy or difficult depending on what you are asking it to do. Here is a basic example of working code for a sinmple html content email with a linked image. ->

<?php

$headers = "From: you@yourcompany.com\r\nContent-type: text/html";

$body = "<HTML><BODY><CENTER>
<TABLE BORDER='1'><TR><TD align='center'><B><BIG>
Here is an image!</BIG></B></TD></TR>
<TR><TD align='center'><IMG SRC='http://yourserver.com//yourimage.jpg'></TD></TR>
</CENTER></BODY>
</HTML>";

mail("them@theiraddress.com", "HTML EMAIL", $body, $headers);

?>

->
Just make sure you get the content type text/html into the mail headers. As I have said, you can make these as complicated as you want to, but this is a basic example that you can modify and add to and it works. Just make sure you have named your mail server in your PHP configuration (php.ini) file.

Cullan
 
Old September 10th, 2005, 07:13 PM
Registered User
 
Join Date: Sep 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Isnt this linking the images? what did you mean in your original post ?
Another thing you can do similar to what you have here is use the
Code:
<BASE href=http://domain.com/>
at the top, in the head, then just email the code of the page as is. This is what happens wih IE if you File>Send>Page by Email.

So, I was wondering about what i would call embedding, which is turning the image into a long string of numbers, etc. I would like to see a php function which you could point at a web page, and have it set up an email like that.

The reason behind me wanting to do it this way, is that i think you would circumvent the whole 'to protect you privacy, outlook did not download this image' thing. I need to send out emails that will just work, without the user having to think.

--
juglesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Embed image into email rpkbuddhi PHP How-To 2 December 17th, 2008 07:37 PM
Email html format with image robprell Perl 3 May 9th, 2007 05:20 PM
Embed Image in HTML Email cullancrothers Pro PHP 4 June 22nd, 2005 01:40 PM
embed images in html allang Pro JSP 0 August 22nd, 2004 09:43 PM
Embed report into email message. liliarum BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 July 8th, 2004 01:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.