Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending mass email with images 2

Status
Not open for further replies.

smashing

Programmer
Oct 15, 2002
170
US
Hi everyone!!
Question: Is there any way I can detect how recipients see their email?
I'm writing a PHP script that will send an email to the hundreds of people, in my MYSQL database - I'm including HTML in this email ('cause I want to display images as well) .
There are people that cannot view any HTML in their email (be it Internet cellphones or otherwise) and there also are people that don't want to see HTML and have chosen the 'view text only' feature in the email program of their choice.
I would prepare an alternate email message without any HTML in it and use an if else statement to send the appropriate form of email message. Any ideas?
 
I'm having problems with this now, altough this may not be a PHP issue but rather plain 'ol HTML related. I think there is a line that has to be put before any html content is put so that the receiving email program knows to expect HTML content, otherwise its all mumble jumble. something like

MIME-Version: 1.0
Content-Type: multipart/alternative;
or
Content-Type: text/html;

Anybody know?
 
/* header info */
$headers = "MIME-Version: 1.0\n";
$headers .= 'Content-Type: multipart/alternative; boundary="myboundary";';
 
Usually people make up a random string for the boundary parameter.
It serves to delmit the alternate parts of the messages i.e. plain text and HTML or attachments.
 
Please DRJ478 !

Explain the boundry part with a little more detail or show an example

Thanks
 
We are talking RFC 1521 here:

A typical multipart Content-Type header field might look like this:
Code:
Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU4gI32
This indicates that the message consists of several parts, each itself with a structure that is a message, except that the header area might be completely empty, and that the parts are each preceded by the line
Code:
--gc0p4Jq0M2Yt08jU4gI32
The encapsulation boundary must occur at the beginning of a line following a CRLF., and that the initial CRLF is considered to be attached to the encapsulation boundary rather than part of the preceding part.
The boundary must be followed immediately either by another CRLF and the header fields for the next part, or by two CRLFs, in which case there are no header fields for the next part (and it is therefore assumed to be of Content-Type text/plain).

Body parts that must be considered to end with line breaks, therefore, must have two CRLFs preceding the encapsulation line, the first of which is part of the preceding body part, and the second of which is part of the encapsulation boundary.
Important: Encapsulation boundaries must not appear within the encapsulations, and must be no longer than 70 characters, not counting the two leading hyphens.
The encapsulation boundary following the last body part is a distinguished delimiter that indicates that no further body parts will follow. Such a delimiter is identical to the previous delimiters, with the addition of two more hyphens at the end of the line:
--gc0p4Jq0M2Yt08jU4gI32--

You can read to your hearts content the whole RFC 1521 specification:

Again, will do all this for you.
 
Dear DRJ478
I downloaded the php mailer from like you suggested but I see that it involves writing inside the php.ini file, something i am very uncomfortable with and my web host dosen't want to support. I'm going round and round in a circle for more than a week with this already, so I'll post the script here & please help me with this:

//first get all email addresses from database
$get_all_address = "SELECT eadd FROM testcust";
$result = @mysql_query($get_all_address, $connection)or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$msg =&quot;<html><head><style type=\&quot;text/css\&quot; media=\&quot;screen\&quot;><!--
h2 { color: #00639c; font-size: 14pt; font-family: Verdana }
h6 { color: #00639c; font-size: 9pt; font-family: Verdana }
h5 { color: #00639c; font-size: 10pt; font-family: Verdana }
p { color: #f00; font-size: 7pt; font-family: Verdana }
--></style></head><body><div align=\&quot;center\&quot;>
<img src=\&quot; height=\&quot;164\&quot; width=\&quot;461\&quot; border=\&quot;0\&quot;></div><h5>We at Washington Deluxe Bus Co. are always ready to serve you with our famous daily Bus service between Washington DC and New York.</h5>
<p><p><h6>Check out our special schedule for Memorial Day - May 26 '03 - by clicking <a href=\&quot; If you wish to be removed from our mailing list and not receive emails such as this one in the futre - Click <a href=\&quot;
$to =&quot;$row[eadd], &quot;;
$subject =&quot;Check out our Memorial Day Schedule&quot;;
//$mailheaders =&quot;MIME-Version: 1.0\n&quot;;
//$mailheaders .= 'Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU4gI32';
$mailheaders  = &quot;MIME-Version: 1.0\n&quot;;
$mailheaders .= 'Content-Type: multipart/mixed; boundary=&quot;gc0p4Jq0M2Yt08jU4gI32&quot;;';
$mailheaders .= &quot;From:<info@washny.com>\n&quot;;
$mailheaders .=&quot;Reply-To:info@washny.com\n\n&quot;;

//send the mail
mail($to, $subject, $msg, $mailheaders);
}



The more I play around with the Content-Type line the funnier the outcome. Currently nothing at all is diplayed my email program if this script is activated.
 
You need not alter the php.ini to use phpmailer. The recommendation they give on the site does not mention that you can just include the file using the system level file path:

require('/myhome/phpmailer/class.phpmailer.php');

That will make it much easier.

 
Please can you show me what to put into the script code that I posted and where ( I think I only need 2 lines)

I beg you please please please!!!!!!!
 
smashing,

You need to assemble the message in parts. One part plain text, the alternate part HTML:
Code:
$header  = &quot;MIME-Version: 1.0\n&quot;;
$header .= 'Content-Type: multipart/alternative; boundary=&quot;XXMail12345&quot;;';
        
# create a multipart message with HTML last
$body = &quot;\r\n--XXMail12345\r\n&quot;;
# plain text first
$body .= &quot;Content-type: text/plain; charset=iso-8859-1\r\n\r\n&quot;;
# this hold your plain text
$body .= $myText;
$body .= &quot;\r\n--XXMail12345\r\n&quot;;
$body .= &quot;Content-type: text/html; charset=iso-8859-1\r\n\r\n&quot;;
# here comes the HTML part
$body .= $myHTML;
$body .= &quot;\r\n--XXMail12345--\r\n&quot;;

All right?
You haven't composed the text message in your code. You need to do that.
 
for the php ini stuff I just use
ini_set(&quot;include_path&quot;, $doc_root);
// where $doc_root is the path to the folder which
// holds my php files
in a file that gets included into every page of my application (I don't actually include it into every file, but with the way I have structured my application and include_once(...) it's basically the same effect).

This seems to work. I'm about to use upload phpmailer to my host in the next couple of days, so I'll see if it works. But prior to doing this I had problems, especially with functions that I was calling which were in their own 'functions' folder, I was getting errors that the php include path didn't contain my functions, this fixed it.

The New Zealand Site
 
Sorry the backslashes got messed up in my post - copied from Linux.
They look like strike-through W.

;)
 
THANKS DRJ478
Everything works now, You made my day!!!

Not untill you posted the example yesterday, did I get it.

THANKS AGAIN !!!!
 
What's happening now though is this:

$mailheaders =&quot;From:info@washny.com<>\n&quot;;
$mailheaders .=&quot;Reply-To:info@washny.com\n\n&quot;;
$mailheaders .= &quot;MIME-Version: 1.0\n&quot;;
$mailheaders .= 'Content-Type: multipart/alternative; boundary=&quot;XXMail12345&quot;;';
Written as above will display From:info@washny.com like I want it do, but the content of the email is screwed up. I guess the very first line of the headers should be the MIME etc.

So if I reverse the order to read:

$mailheaders = &quot;MIME-Version: 1.0\n&quot;;
$mailheaders .= 'Content-Type: multipart/alternative; boundary=&quot;XXMail12345&quot;;';
$mailheaders .=&quot;From:info@washny.com<>\n&quot;;
$mailheaders .=&quot;Reply-To:info@washny.com\n\n&quot;;

Then the message inside the email is beutifully displayed as I want it with the nessecary HTML etc., but the From line displays myusername@mysite.com - something that I don't want the rceiving end to see!
What next ???
 
This is next:

You can set the from address PHP sends as using the following command:
Code:
ini_set(&quot;sendmail_from&quot;,&quot;me@mydomain.com&quot;);

It will give you the desired result. Of course, set it before issuing the mail() command.
 
Alas!
Tried that - but see no noticible difference at all.
What else can I do if anyyhing ?
Please continue the good work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top