#!/usr/local/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
else { $INPUT{$name} = $value; }
}
$pid = fork();
print "Content-type: text/html \n\n fork failed: $!" unless defined $pid;
if ($pid) {
print "Content-type: text/html \n\n";
print "<html><head><title>List Administration</title></head><body>
<br><br><br><center>
<table width=280><tr><td width=280 valign=top>
<table width=\"280\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" bordercolor=\"#808080\" bordercolorlight=\"black\" bordercolordark=\"white\">
<tr><td bgcolor=\"#0000A0\">
<font face=\"arial\" size=\"2\" color=\"white\"><b>Send Status</b>
</td></tr><tr><td bgcolor=\"#C0C0C0\"><font face=\"arial\" size=\"2\">
<br><center>Success!<BR>The message was sent.
<P><FORM><INPUT TYPE=BUTTON VALUE=\"Return to MLM\" onClick=\"history.go(-1)\"></form>
</td></tr></table></td></tr></table>
</center></body></html>";
exit(0);
}
else {
close (STDOUT);
open(LIST,"$INPUT{'address_file'}");
@addresses=<LIST>;
close(LIST);
foreach $line(@addresses) {
chomp($line);
open(MAIL, "¦$INPUT{'mail_prog'} -t") ¦¦ &error("Could not send out emails");
print MAIL "To: $line \n";
print MAIL "From: $INPUT{'listname'} <$INPUT{'from'}>\n";
print MAIL "Subject: $INPUT{'subject'}\n";
if ($INPUT{'html'}) {
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: text/html;\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
}
print MAIL "$INPUT{'body'}";
if ($INPUT{'html'}) {
print MAIL "<p>";
} else {
print MAIL "\n\n";
}
if ($INPUT{'unsubchk'}) {
print MAIL "===========================================================\n";
print MAIL "You have received this email because you subscribed to the $INPUT{'listname'} Mailing Service. ";
if ($INPUT{'html'}) {
print MAIL "To unsubscribe <a href=\"$INPUT{'url'}/unsub.php?list=$INPUT{'list'}&email=$line\">click here</a>\n";
} else {
print MAIL "To unsubscribe simply visit the link below.\n";
print MAIL "$INPUT{'url'}/unsub.php?list=$INPUT{'list'}&email=$line\n";
}
}
print MAIL "\n\n";
close (MAIL);
}
}
You have come to a great place with lots of helpful people around to answer your questions. Unfortunately the type of question you asked is one that is discouraged in this forum.
There is a nice introduction to Sending MIME e-mail from PHP [zend.com] at zend.com. Contrary to what the title may suggest, these articles are not PHP specific. If you want to learn more about MIME types this is a great place to start.
Adjusting your script to send multipart/alternative mails would involve changing the mail headers at the following lines:
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: text/html;\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: multipart/alternative;\n";
print MAIL qq{boundary="aaron-14";\n};
Then you would need to start each part with "--aaron-14" and the Content-Type and Content-Transfer-Encoding headers specific to that part.
End your message with the boundary string followed by two dashes.
Hope this helps
Andreas
Thanks for that. Do I need to also change this part of the script to reflect the multipart/alternative Content-type?
$pid = fork();
print "Content-type: text/html \n\n fork failed: $!" unless defined $pid;
if ($pid) {
print "Content-type: text/html \n\n";
Does anything need to be done on the server side of things to allow for multipart/alternative content-type to be processed correctely?
So far, I tried modifying the script as you said and send a email through and the email got delivered but as plain text without taking the boundaries into account. (both the plain text and html version of the email were displayed) I'm confused...
Do I need to also change this part of the script
No you donīt, since that is part of the header for the HTML document you are generating with print "<html><head><title>List Administration</title></head><body>...
Does anything need to be done on the server side of things to allow for multipart/alternative content-type to be processed correctely?
No if you can send mail you can send multipart/alternative mail as well. All processing of the multipart mail needs to be done by the mail user agent (MS Outlook, Eudora, etc).
Did you try to reproduce one of the example mails given in the article? If you canīt get it to work post the source code of the email.
Andreas
Content-Type: multipart/alternative;
boundary="mike-14";
--mike-14
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hey Joe! I just thought you'd like this website:
[zend.com...]
--mike-14
Content-Type: text/html
Content-Transfer-Encoding: 7bit
<B>Hey Joe! I just thought you'd like this website:</B><BR>
<a href="http://www.zend.com/"><img src="http://www.raybrown.biz/images/ray.jpg" width="75" height="97" border="5"></a>
--mike-14--
I tried adding the MIME info to the source code. Not sure if I got it right though. Here is what I tried but to no avail as I still get just the source code in the body of my email in the end. What's wrong with my source email code? thanks for your help once again!
Content-Type: multipart/alternative;
MIME-Version: 1.0
boundary="mike-14";
--mike-14
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hey Joe! I just thought you'd like this website:
[zend.com...]
--mike-14
Content-Type: text/html
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<body bgcolor="#000000" text="#999999">
<B>Hey Joe! I just thought you'd like this website:</B><BR>
<a href="http://www.zend.com/"><img src="http://www.raybrown.biz/images/ray.jpg" width="75" height="97" border="5"></a>
</body>
</html>
--mike-14--
Now you have:
Content-Type: multipart/alternative;
MIME-Version: 1.0
boundary="mike-14";
The right one must be:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="mike-14";
Ah don't forget the double CR before the first boundary
[But I think you've already made so :)].
cminblues
<added>BTW, andreasfriedrich's posts are correct about this. :) </added>
#!/usr/local/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
else { $INPUT{$name} = $value; }
}
$pid = fork();
print "Content-type: text/html \n\n fork failed: $!" unless defined $pid;
if ($pid) {
print "Content-type: text/html \n\n";
print "<html><head><title>List Administration</title></head><body>
<br><br><br><center>
<table width=280><tr><td width=280 valign=top>
<table width=\"280\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" bordercolor=\"#808080\" bordercolorlight=\"black\" bordercolordark=\"white\">
<tr><td bgcolor=\"#0000A0\">
<font face=\"arial\" size=\"2\" color=\"white\"><b>Send Status</b>
</td></tr><tr><td bgcolor=\"#C0C0C0\"><font face=\"arial\" size=\"2\">
<br><center>Success!<BR>The message was sent.
<P><FORM><INPUT TYPE=BUTTON VALUE=\"Return to MLM\" onClick=\"history.go(-1)\"></form>
</td></tr></table></td></tr></table>
</center></body></html>";
exit(0);
}
else {
close (STDOUT);
open(LIST,"$INPUT{'address_file'}");
@addresses=<LIST>;
close(LIST);
foreach $line(@addresses) {
chomp($line);
open(MAIL, "¦$INPUT{'mail_prog'} -t") ¦¦ &error("Could not send out emails");
print MAIL "To: $line \n";
print MAIL "From: $INPUT{'listname'} <$INPUT{'from'}>\n";
print MAIL "Subject: $INPUT{'subject'}\n";
if ($INPUT{'html'}) {
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: multipart/alternative;\n";
print MAIL qq{boundary="mike-14";\n};
}
print MAIL "$INPUT{'body'}";
if ($INPUT{'html'}) {
print MAIL "<p>";
} else {
print MAIL "\n\n";
}
if ($INPUT{'unsubchk'}) {
print MAIL "===========================================================\n";
print MAIL "You have received this email because you subscribed to the $INPUT{'listname'} Mailing Service. ";
if ($INPUT{'html'}) {
print MAIL "To unsubscribe <a href=\"$INPUT{'url'}/unsub.php?list=$INPUT{'list'}&email=$line\">click here</a>\n";
} else {
print MAIL "To unsubscribe simply visit the link below.\n";
print MAIL "$INPUT{'url'}/unsub.php?list=$INPUT{'list'}&email=$line\n";
}
}
print MAIL "\n\n";
close (MAIL);
}
}
Your actual:
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: multipart/alternative;\n";
print MAIL qq{boundary="mike-14";\n};
The correct one:
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: multipart/alternative; ";
print MAIL "boundary=\"mike-14\";\n\n";
cminblues
Thanks again!