Page 1 of 1

Send image

Posted: Tue Feb 13, 2007 3:28 pm
by ayoksus
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi there,

I'm a php newbie and have very little knowledge about php, but I like to learn more about it. I help some friends to build in their website for my excersice. Now I have a question about sending an image to email with php. 

I found a tutorial about newsletter, and made a simple newsletter based on the tutorial. I just fill in the list of emails into a .txt database, and fill in a form to send the news. It works fine. But I'd like to have an image on the top of the news. I've tried to figure it out, but no result. I can't find any tutorial about it. 

Perhaps anybody can help me? This is the send.php file, where the news will be sent.

Code: Select all

<?php
include "config.php";
include "header.inc";
if(!($sendmail)){
?>

<form method="POST" action="<?php echo($PHP_SELF); ?>">
 
<h3>News </h3>
  <p>Select Mailing List:<br>
  <select size="1" name="list_choice">
    <option selected>emails.txt</option>
    
  </select></p>
  <p>Title:<br>
  <input type="text" name="subject_choice" size="50"></p>
  <p>Message:<br>
  <textarea rows="6" name="message_choice" cols="42"></textarea></p>
  <p><input type="submit" value="Send Mail" name="sendmail"><input type="reset" value="Reset" name="B2"></p>
</form>
</UL>
<?php
}
//from config.php
$header = "From: $from_mail; \n";
if ($sendmail == "Send Mail"){

print ("<H3>Sending news to emails...</H3><P>");

$file_handle = fopen($list_choice, "r") or die("Couldn't open mailing list..");

while (!feof($file_handle)) {
set_time_limit(0);
$address = fgets($file_handle, 1024);

mail("$address", stripslashes($subject_choice), 
	stripslashes($message_choice), $header);
print ("Mail Sent To: $address<br>\n");

}
print ("<H3>Done! The news is sent.  Klik <A HREF='view.php'>Click here</A> to see the emails.</H3><BR>");
}
include "footer.inc";
?>
Could anybody help me here?

Thanx in advanced,
ayoksus


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Feb 14, 2007 2:40 am
by ayoksus
Nobody understand my question?
What I'm trying to achieve here is to send an email with an image in it. Like a letter with an image header/footer.

Thx
ayoksus

Posted: Wed Feb 14, 2007 6:39 am
by louie35
look into formating the email as html then just add the image code as you do on a normal page

Code: Select all

<img src="path here" />

Posted: Wed Feb 14, 2007 7:17 am
by ryuuka
hint for e-mail html formatting:

Code: Select all

$message= ("
		<html> 
		 <body bgcolor='#ffffff'>  
		 <br>
			'the message goes here. <br> 
			 as you can seen it's the same as a html page <br>
		 </body>
		</html>"); 

	$headers  = "From: billgates@satanic.org\r\n"; 
	$headers .= "Content-type: text/html\r\n";   // <------ note the html header type
	
	mail("$recieve_mail", "php and html mail",
	"$message",
	  "$headers"
	  );
good luck and let us know how it goes

EDIT: it showed my companies name and i missed a few things

Posted: Wed Feb 14, 2007 7:35 am
by ayoksus
Thx for the replies guys,

I've tried to set the email as html. I think that's the only way. I put the html code "Content-type: text/html\r\n" in the $header.
As you can see in my php file, the message ($message_choice) is the body of the email. The body(message) will be sent to the emails after I submit the message.

Therefore, to get an image on the email's body, I need to type in this code "<img src="path here" />" everytime I submit the news. And one more thing.. because the message will be sent as html, then I have to type <BR> everytime i want to get a new line. I don't think it's efficient..

How can i include the pic into $message_choice?

Posted: Wed Feb 14, 2007 7:51 am
by louie35
it looks like you want to be lazy about it.

try

Code: Select all

str_replace("\n\r","<br />", $string);

Posted: Wed Feb 14, 2007 11:47 am
by ayoksus
hehe.. thx.. I just want to make it easy because there will be someone else who fill in the form.

I have no more problem with the image since I send the email with html format. But now the problem is that I can't send the emails to HOTMAIL (and some addresses).. What's wrong with hotmail? I can send emails to yahoo or gmail..

Thank you
ayok