Current location: Hot Scripts Forums » Programming Languages » PHP » Mime and Inline Images


Mime and Inline Images

Reply
  #1 (permalink)  
Old 04-28-05, 06:42 PM
AdamOhio76 AdamOhio76 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Mime and Inline Images

I am looking to find a "simple" example of sending Mime E-mails with Inline images. I have an example of what I want below.

The message should have the logo at the top, the message and finally the footer. The goal to create a form to allow end-users to simply type their message and click send and the email format properly without intervention or coding knowledge.

Anyone have thoughts?

Thanks for your time!!

Code:
<?php
	
	if($cmd=="sendmessage")	{
		
		$headers = "From: $fr_sender\n";
		$headers .= "MIME-Version: 1.0\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1";
		
		$top_image = "http://www.mysite.org/graphics/toplogo.gif";
		$bottom_image = "http://www.mysite.org/graphics/bottomlogo.gif";
		
		$email_message = "
			<html>
			<body>
				<img src='$top_image'>
				<br>
					$fr_message<br>
				<br>
				<img src='$bottom_image'>
			</body>
			</html>
		";
		
		
		mail($fr_receipient,$fr_subject,$email_message,$headers);
		
		$message="Your message has been sent";
		$cmd="";
		//header("Location: mailsender.php?msg=$message");
		echo"Receipient: $fr_receipient<br>Sender: $fr_sender<br>Message<br>$email_message";
		exit();
	}
?>
Reply With Quote
  #2 (permalink)  
Old 04-28-05, 07:23 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
if the images are not attachments and are hosted in a website, simply use HTML to send the email with images inside it (with <img> tag)
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 04-28-05, 10:34 PM
AdamOhio76 AdamOhio76 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by NeverMind
if the images are not attachments and are hosted in a website, simply use HTML to send the email with images inside it (with <img> tag)
This was the first thing I attempted. When I sent the email with the img tags I wouldn't receive an email. However, when I comment the img tags out the email goes through.

Something within the img tag is keeping it from sending the email.

See the below reformatted code.

Code:
<?php
	
	if($cmd=="sendmessage")	{
		
		$headers = "From: $fr_sender\n";
		$headers .= "MIME-Version: 1.0\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1";
		
		$email_message = "<html>";
		$email_message .="<body>";
		//$email_message .="<img src=\"http://www.mysite.org/graphics/toplogo.gif\" alt=\"\" height=\"96\" width=\"901\" border=\"0\">";
		$email_message .="<br>";
		$email_message .="$fr_message<br>";
		$email_message .="<br>";
		//$email_message .="<img src=\"http://www.mysite.org/graphics/bottomlogo.gif\" alt=\"\" height=\"96\" width=\"901\" border=\"0\">";
		$email_message .="</body>";
		$email_message .="</html>	";
		
		
		mail($fr_receipient,$fr_subject,$email_message,$headers);
		
		$message="Your message has been sent";
		$cmd="";
		//header("Location: mailsender.php?msg=$message");
		echo"Receipient: $fr_receipient<br>Sender: $fr_sender<br>Message<br>$email_message";
		exit();
	}
?>
Reply With Quote
  #4 (permalink)  
Old 05-02-05, 03:31 PM
AdamOhio76 AdamOhio76 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Anyone have any thoughts? Am I coding this incorrectly?

Thanks for your time.
Reply With Quote
  #5 (permalink)  
Old 05-02-05, 06:02 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
after taking a look the this peice of code I found:
* you didn't use \r\n after each header which is a must as PHP manual says:
Quote:
Note: You must use \r\n to separate headers, although some Unix mail transfer agents may work with just a single newline (\n).
* the mail() function is not taking the headers variable correctly! there is a tab between the dollar sign $ and the name of the variable!

try this one instead:
PHP Code:

    if($cmd == 'sendmessage')    {

        
        
$headers "From: $fr_sender\r\n";
        
$headers .= "MIME-Version: 1.0\r\n";
        
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        
        
$email_message '<html>';
        
$email_message .='<body>';
        
$email_message .='<img src="http://www.mysite.org/graphics/toplogo.gif" alt="" height="96" width="901" border="0">';
        
$email_message .="<br>";
        
$email_message .="$fr_message<br>";
        
$email_message .='<br>';
        
$email_message .='<img src="http://www.mysite.org/graphics/bottomlogo.gif" alt="" height="96" width="901" border="0">';
        
$email_message .='</body>';
        
$email_message .='</html>';
        
        
        
$check = @mail($fr_receipient$fr_subject$email_message$headers);
        
        if (!
$check)
           die(
'Mail was not sent!');
        
        
$message"Your message has been sent";
        
$cmd "";
        
//header("Location: mailsender.php?msg=$message");
        
echo"Receipient: $fr_receipient<br>Sender: $fr_sender<br>Message<br>$email_message";
        exit();
    } 
however, some spam filters consider a message a spam when it contains inline images! so check out your junk/bulk mail..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #6 (permalink)  
Old 05-03-05, 06:30 AM
AdamOhio76 AdamOhio76 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Nevermind:

Thank you for all your help. After reviewing your response I did check my Julk Mail and found the 20 or so tests I sent that did work.

When my mail client didn't indicate any received messages, I just assumed they never sent. They were there the whole time and did work correctly as I had them coded.

I do appreciate you pointing out the \r\n coding as I did miss that.

Your time is greatly appreciated.

Adam
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.