Click to See Complete Forum and Search --> : sending html mails with mailto:


jasperlevink
01-05-2005, 12:28 PM
Hello folks!

My client likes to send mailings to a list of clients with his latest column. No problem, if there would be only the column (loaded from the DB). But my client wants to be able to ad some text and change the font etc if necessary.

There are two possibilities to do this: Me creating an on-line editor or something i'm not sure of wheter it will work:

With mailto: in the link element (<a> ) it is possible to open the user's e-mail client with a pre-determined title and content:

<a href="mailto:user1@mailinglist.nl,user2@mailinglist.com?subject=mailing&body=basic content">send!</a>

I'd like this basic content to be some html code.

How can I tell the mail-client (MS outlook 2000 in this case) that we are writing a html mail? body=<html>content</html> is not enough.

How can I attach pictures to the e-mail and use them in the mail?

Thanks.
Jasper

PS.: I'm sorry for my lacky English...

rhsunderground
01-05-2005, 12:32 PM
it is possible with php. do you have php abilities?

jasperlevink
01-05-2005, 12:37 PM
yes i do! Tell me more!

PS: It would be nice if it is possible not to waste a great amount of time on programming an on-line mail editor

linyujac11
01-05-2005, 01:01 PM
Hello rhsunderground,

can you explain how to attach files (ASCII) to a mail ?

thanks.
Bruno.

rhsunderground
01-05-2005, 01:06 PM
alrighty. here's what you need to mail:
<html>
<head>
<title>Email Form</title>
</head>
<body>
<form action="emailform.php" method="post">
Name:<input type="text" name="username" size="30" value="Your Name">
<br /><br />
E-mail:<input type="text" name="useraddr" size="30" value="mail@mailer.com">
<br /><br />
<textarea name="content" cols="50" rows="20">
</textarea><br />
<input type="submit" value="Send Mailer">
</form>
</body>
</html>

and emailform.php:

<? $username = $_POST['username'};
$useraddr = $_POST['useraddr'};
$content = $_POST['content'};

$to = "user1@mailinglist.nl,user2@mailinglist.com";
$re = "Mailing List";
$msg = $content;
$headers = "MIME-Version: 1.0\r\n"; #html headers
$headers .= "Content-type: text\html;";
$headers .= " charset=iso-8859-1\r\n";
$headers .= "From: $useraddr \r\n";
$headers .= "Cc: anotherperson@mail.com \r\n"; #cc
mail( $to, $re, $msg, $headers );
?>
<html>
<head><title>Mailer sent</title></head>
<body>
<p>Message sent.</p>
</body></html>


try that.

jasperlevink
01-05-2005, 01:20 PM
Now I can type a HTML message?

Can't I use the header-info with mailto:?

The problem is that my client is not a html-pro.. So I'd prefer a solution where there is no html visible! nevertheless thanks for your reaction!

rhsunderground
01-05-2005, 01:25 PM
to attach:
<html><head><title>Attachment form</title></head>
<body>
<form action="sendmixed.php" method="post" enctype="multipart/form-data">
To: <input type="text" name="to" size="40">
<br /><br />
From: <input type="text" name="from" size="40">
<br /><br />
Subject: <input type="text" name="re" size="40">
<br /><br />
Message: <textarea cols="30" rows="5" name="comments"></textarea>
<br /><br />
Attachment: <input type="file" name="att" size="26">
<br /><br />
<input type="submit" value="Send Form">
</form>
</body></html>

and sendmixed.php :
<$php
$to = $_POST['to']; $from = $_POST['from'];
$re = $_POST['re']; $comment = $_POST['to'];

$att = $_FILES['att'];
$att_path = $_FILES['att']['tmp_name'];
$att_name = $_FILES['att']['name'];
$att_size = $_FILES['att']['size'];
$att_type = $_FILES['att']['type'];

$fp = fopen( $att_path, "rb");
$file = fread( $fp, $att_size );
fclose( $fp );

$num = md5(time());
$str = "==Multipart_Boundary_x{$num}x";

$file = chunk_split(base64_encode($file));

$hdr = "MIME-Version: 1.0\r\n";
$hdr .= "Content-type: texthtml; ";
$hdr .="boundary=\"{$str}\"\r\n";
$hdr .= "From: $from \r\n";

$msg = "This is a multi-part message in MIME format\r\n\n";
$msg .= "--{$str}\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\" \r\n";
$msg .= "Content-Transfer-Encoding: 8bit\r\n;"
$msg .= "$comments\r\n\n";
$msg .= "--{$str}\r\n";

$msg .= "Content-Type" {$att_type}; ";
$msg .= "name=\"{$att_name}\"\r\n";
$msg .= "Content-Transder-Encoding: base64\r\n";
$msg .= "$file\r\n\n";
$msg .= "--{$str}";

$ok = mail( $to, $re, $msg, $hdr );
if( $ok ) echo "OK";
?>
i hope that both of those work.

rhsunderground
01-05-2005, 01:27 PM
Originally posted by jasperlevink
Now I can type a HTML message?

Can't I use the header-info with mailto:?

The problem is that my client is not a html-pro.. So I'd prefer a solution where there is no html visible! nevertheless thanks for your reaction! you should be able to use html code with that, yes. but to enable idiot-proof mailings, you need much more powerful PHP, such as the PHP that is used in these forums to create the vB Code.

linyujac11
01-05-2005, 01:41 PM
thanks a lot !!!

Bruno. :)

jasperlevink
01-05-2005, 01:41 PM
Then we'll have to do it with this! Thanks!

I don't understeand how to insert images and use them in the message. Is that the $msg .= "$file\r\n\n"; part?

thanks.

rhsunderground
01-05-2005, 10:09 PM
Originally posted by jasperlevink
Then we'll have to do it with this! Thanks!

I don't understeand how to insert images and use them in the message. Is that the $msg .= "$file\r\n\n"; part?

thanks. can't you just use <img src="http://www.site.com/Images/image.gif" /> ?

MstrBob
01-05-2005, 10:22 PM
Whoah, Skinner does PHP now? :p Might I suggest NOT using HTML in emails, as not all Email clients support HTML and it will come out as a garbled mess. Use plain text if available.

rhsunderground
01-05-2005, 10:28 PM
Originally posted by MstrBob
Whoah, Skinner does PHP now? i bought maself a php book :cool:

jasperlevink
01-06-2005, 04:27 AM
Most mail-clients automatically block images from the internet in mails. Because they are often used to verify a users mail adress!