Location: PHPKode > scripts > libMail > libmail/libmail_en.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
body {
	background-color: #ffffff;
	margin-top: 20px;
	margin-bottom: 20px;
	margin-left: 20px;
	margin-right: 20px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}

code {
	color: #209090;
	font-weight: bold;
}

pre {
	font-family: monospace;
	font-size: 90%;
	color: #209090;
	margin-left: 1em;
}

p {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	text-align: justify;
	margin-left: +30px;
}	

ul {
	list-style: circle;
	margin-left: 10px;
}

ol {
	list-style: upper-roman;
}

h1,h2,h3,h4,h5,h6 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	color: maroon;
}

h1 {
	font-size: +2em;
}

h2 {
	margin-left: +10px;
	text-decoration: underline;
}

h3 {
	margin-left: +20px;
	text-decoration: underline;
}

h4 {
	margin-left: +30px;
	font-weight: bold;
}


.aIdx {
	color: blue;
	font-weight: bold;
	text-decoration: none;
	vlink-color: darkblue;
	
}
.aIdx:active { color: pink; }

TABLE.params {
	border-collapse: collapse;
	border: 1px;
	background-color: #dddddd;
	padding: 1 5 1 5;
}
</style>
</head>
<body bgcolor="white">
<a name="LIBMAIL"></a>
<h1>LIBMAIL</h1>
<p><a name="Description"></a>
<h2>Description</h2>
<p>This library offers an object oriented way to send email from a PHP program. 
<p><a href="#Summary">Show summary</a> 
<p><b>Important!</b> users of 1.2 version , download the last version. A bug in 
  v1.2. was impacting file attachment functionnality. 
<p><a name="License"></a>
<h2>License</h2>
<p> This script is distributed under the <a href="http://www.gnu.org/licenses/gpl.txt" target="_blank">GPL 
  License</a><br>
  <br>
  This program is distributed in the hope that it will be useful, but WITHOUT 
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 
<p>
<p><a name="License"></a>
<h2>Authors</h2>
<p> This script is an extensions of original libMail by <a href="mailto:%hide@address.com">Leo 
  West</a><br>
  <br>
  Original script by Leo West - <a href="mailto:hide@address.com">hide@address.com</a><br>
  URL: <a href="http://lwest.free.fr/doc/php/lib/Mail/" target="_blank">http://lwest.free.fr/doc/php/lib/Mail/</a><br>
  Lastmod : Nov 2001<br>
  Version : 1.3<br>
  <br>
  Modified by Setec Astronomy - <a href="mailto:hide@address.com">hide@address.com</a><br>
  URL : <a href="http://digilander.iol.it/setecastronomy/" target="_blank">http://digilander.iol.it/setecastronomy/</a><br>
  Lastmod : Gen 2004<br>
  Version : 1.4
<p>
<p>Some of the libMail functionalities are : 
<p>
<ul>
  <li> Sending one or more file in attachment 
  <li> Specify one or many recipients in To, CC or BCC 
  <li> Format a message "ready to send" without sending it immediately 
  <li> Auto checking of email addresses syntax 
  <li> Add a receipt to the mail 
</ul>
<p>
<p>
<p><a name="ChangeLog"></a>
<h2>ChangeLog</h2>
<p><b>version 1.4</b>
<ul>
  <li> added ReturnPath ($returnpath_email, $returnpath_name = &quot;&quot;) method 
  <li> modified ReplyTo, From methods 
  <li> modified To, CC, BCc methods 
  <li>added AntiSpamming () method 
  <li>removed autoCheck features
</ul>
<p><b>version 1.3</b> 
<ul>
  <li> BUG FIX - file attachment didn't work 
  <li> serious rewrite of the class 
  <li> small optimization in _build_attachement() 
</ul>
<p><b>version 1.2</b> 
<ul>
  <li> added ReplyTo( $address ) method 
  <li> added Receipt() method to add a mail receipt 
  <li> added optional charset parameter to Body() method . should fix charset 
    problem on some mail clients 
</ul>
<p><b>version 1.1</b> 
<ul>
  <li> added optional mimetype and disposition parameters to Attach() method 
  <li> fixed parenthesis bug in sizeof() 
</ul>
<p>
<p><a name="Synopsis"></a>
<h2>Synopsis</h2>
<p> 
<pre>	include &quot;libmail.php&quot;;
	$m= new Mail; // create the mail
	$m-&gt;From (&quot;hide@address.com&quot;);
	$m-&gt;To (&quot;hide@address.com&quot;);
	$m-&gt;Subject (&quot;the subject of the mail&quot;);
	$m-&gt;Body (&quot;Hello\nThis is a test of the Mail component&quot;);	// set the body
	$m-&gt;Cc (&quot;hide@address.com&quot;);
	$m-&gt;Bcc (&quot;hide@address.com&quot;);
	$m-&gt;Priority (4) ;	// set the priority to Low
	$m-&gt;Attach (&quot;/home/leo/toto.gif&quot;, &quot;image/gif&quot;, &quot;inline&quot;) ;	// attach a file of type image/gif to be displayed in the message if possible
	$m-&gt;Send ();	// send the mail
	echo &quot;Mail was sent:&lt;br&gt;&lt;pre&gt;&quot;, $m-&gt;Get (), &quot;&lt;/pre&gt;&quot;;
</pre>
<p><a name="Installation"></a>
<h2>Installation</h2>
<p>
<p>Download <a href="libmail.zip">libmail.zip</a> 
<p>Content: 
<p> 
<ul>
  <li> <b>libmail.php</b>: the Mail component 
  <li><b>libmail_en.html</b>: documentation in english 
</ul>
<p>
<p>No specific configuration is required in the library itself. In php3.ini (php.ini 
  for PHP4): 
<ul>
  <li> configure the sendmail address <i>sendmail_from</i> 
  <li> configure the SMTP server host <i>SMTP</i> 
</ul>
<p> 
<pre>	SMTP           = hide@address.com			; for win32 only
	sendmail_from  = hide@address.com	;for win32 only
</pre>
<p><a name="Documentation"></a>
<h2>Documentation</h2>
<p>
<p><a name="Constructor"></a>
<h4>Constructor</h4>
<p>Create an instance of a Mail. 
<p> 
<pre>	$mail = new Mail ();
</pre>
<p><a name="Subject%28+string+sujet+%29"></a>
<h4>Subject ([string subject])</h4>
<p>Defines the mail subject line. optional. 
<p> 
<pre>	$mail-&gt;Subject (&quot;Hello world!&quot;);
</pre>
<p><a name="From%28+address+%29"></a>
<h4>From (string from_email, [string from_name])</h4>
<p>Defines the mail sender. call <b>required</b>. You can also specify the sender 
  name. 
<p> 
<pre>	$mail-&gt;From( &quot;hide@address.com&quot; );
	$mail-&gt;From( &quot;hide@address.com&quot;, &quot;Me at ISP&quot; );
</pre>
<p><a name="To%28+mixed+address+%29"></a>
<h4>To (mixed address)</h4>
<p>Defines the recipient(s). call <b>required</b>. The address parameter can be 
  either an address (string) or an array of addresses. You can also specify the 
  recipient(s) name.
<p> 
<pre>	$mail-&gt;To (&quot;hide@address.com&quot;);
</pre>
<pre>	$tos = array (&quot;hide@address.com&quot;, &quot;hide@address.com&quot;);
	$mail-&gt;To ($tos);
</pre>
<pre>	$tos = array (&quot;hide@address.com&quot; =&gt; &quot;You at ISP&quot;, &quot;hide@address.com&quot; =&gt; &quot;U2 at ISP&quot;);
	$mail-&gt;To ($tos);
</pre>
<p>
<p>
<p><a name="CC%28+mixed+address+%29"></a>
<h4>CC (mixed address)</h4>
<p>Defines one or many Carbon-copy recipients. The address parameter can be either 
  an email adress (string) or an array of addresses. You can also specify the 
  recipient(s) name.
<p> 
<pre>	$mail-&gt;CC (&quot;hide@address.com&quot;);
</pre>
<pre>	$ccs = array (&quot;hide@address.com&quot;, &quot;hide@address.com&quot;);
	$mail-&gt;CC ($ccs);
</pre>
<pre>	$ccs = array (&quot;hide@address.com&quot; =&gt; &quot;You at ISP&quot;, &quot;hide@address.com&quot; =&gt; &quot;U2 at ISP&quot;);
	$mail-&gt;CC ($ccs);</pre>
<p> 
<p><a name="BCC%28+mixed+address+%29"></a>
<h4>BCC (mixed address)</h4>
<p>Defines one or many invisible carbon-copy recipients. The address parameter 
  can be either an email adress (string) or an array of addresses. You can also 
  specify the recipient(s) name. 
<p> 
<pre>	$mail-&gt;BCC (&quot;hide@address.com&quot;);
</pre>
<pre>	$bccs = array (&quot;hide@address.com&quot;, &quot;hide@address.com&quot;);
	$mail-&gt;BCC ($bccs);
</pre>
<pre>	$bccs = array (&quot;hide@address.com&quot; =&gt; &quot;You at ISP&quot;, &quot;hide@address.com&quot; =&gt; &quot;U2 at ISP&quot;);
	$mail-&gt;BCC ($bccs);</pre>
<p>
<p>
<p><a name="Body%28+string+body%2C+%5Bstring+charset%5D+%29"></a>
<h4>Body ([string body], [string charset])</h4>
<p>Defines the message body. the optional charset parameter defines the character 
  set used in the message. The default is "us-ascii". Use <b>iso-8859-1</b> charset 
  if your message includes european characters such as accents. 
<p> 
<pre>	$mail-&gt;Body (&quot;Message in english&quot;);
	$mail-&gt;Body (&quot;Message av&eacute; d&eacute; accents&quot;, &quot;iso-8859-1&quot;);
</pre>
Note: Don't send HTML this way. See <a href="#Advices">Advices</a> to send a mail 
in HTML format. 
<p>
<p>
<p><a name="Attach%28+string+filename%2C+%5Bstring+mimetype%5D%2C+%5Bstring+disposition%5D+%29"></a>
<h4>Attach( string filepath, [string mimetype], [string disposition], [string 
  filename] )</h4>
<p>Attach a file $filepath to the mail. 
<p>
<ul>
  <li> <b>filepath</b> : path to the file on drive. </li>
  <li> <b>mimetype</b> : string that defines the file MIME-type. Default MIME 
    is 'application/x-unknown-content-type'. The Mime-Type is used by Email clients, 
    for instance to display an image attached in the mail, or to "automagically" 
    launch an attached virus for some of them :) </li>
  <li> <b>disposition</b> : this code defines the method used to display the attachment. 
    With <b>inline</b> (default), the mail client will display the file directly 
    in the mail if possible. With <b>attachment</b>, the attched file will be 
    presented as a link. </li>
  <li><b>filename</b> : the name displayed by the attached file. </li>
</ul>
<p> 
<pre>	$mail-&gt;Attach (&quot;logo.gif&quot;, &quot;image/gif&quot;);
</pre>
<pre>	$mail-&gt;Attach (&quot;C:\\My Documents\\resume.doc&quot;, &quot;application/x-msword&quot;, &quot;attachment&quot;);
</pre>
<pre>	$mail-&gt;Attach (&quot;C:\\My Documents\\resume.doc&quot;, &quot;application/x-msword&quot;, &quot;attachment&quot;, &quot;cv.doc&quot;);
</pre>
<p>&nbsp; 
<p><a name="Organization%28+string+%24org+%29"></a>
<h4>Organization (string $org)</h4>
<p>Defines the Organization field. Optionnal. 
<p> 
<pre>	$mail-&gt;Organization (&quot;My company&quot;);
</pre>
<p>
<p><a name="ReplyTo%28+string+address+%29"></a>
<h4>ReplyTo (string replyto_email, [string replyto_name])</h4>
<p>Defines a "Reply To" address that is different than the Sender address. You 
  can also specify the Reply To name. 
<p> 
<p><a name="ReplyTo%28+string+address+%29"></a>
<h4>ReturnPath (string returnpath_email, [string returnpath_name])</h4>
<p>Defines a "Return Path" address that is different than the Sender address. 
  You can also specify the Return Path name. 
<p> 
<pre>	$mail-&gt;ReturnPath (&quot;hide@address.com&quot;);
</pre>
<pre>	$mail-&gt;ReturnPath (&quot;hide@address.com&quot;, &quot;My Company Support&quot;);
</pre>
<p> 
<p><a name="Priority%28+integer+%24priority+%29"></a>
<h4>Priority ([integer $priority])</h4>
<p>Defines the mail priority. Optional. 
<p>priority must be an integer between 1 (highest) et 5 ( lowest ) This information 
  is usuall used by mail clients, eg. by highlighting urgent messages. 
<p> 
<pre>	$mail-&gt;Priority (1); // urgent
	$mail-&gt;Priority (3); // normal
	$mail-&gt;Priority (5); // more urgent than all</pre>
<p><a name="Receipt%28%29"></a>
<h4>Receipt ()</h4>
<p>Add a receipt to the mail. This is a mecanism that sends a receipt back to 
  sender when the message is opened by a recipient. The receipt is sent to the 
  address defined in From field, unless if ReplyTo field is defined. 
<p>
<pre>	$mail-&gt;Receipt ();
</pre>
Warning: this mecanism is not standardised, thus not fully supported by mail clients. 
<p>
<p>
<p><a name="Send%28%29"></a>
<h4>Send ()</h4>
<p>Send the mail. Don't forget to call this method :) 
<p>
<p> 
<pre>	$mail-&gt;Send ();
</pre>
<p><a name="Get%28%29"></a>
<h4>Get ()</h4>
<p> 
<pre>	Return the whole email (headers + message + attachments) in raw format.
	Can be used to display the mail, or to save it in a File or DB.
</pre>
<pre>	$msg = $mail-&gt;Get ();
</pre>
<pre>	// display the message on the page
	echo &quot;Your message has been sent:&lt;br&gt;&lt;pre&gt;&quot;, nl2br( $msg ) , &quot;&lt;/pre&gt;&quot;;
</pre>
<pre>	// log it in a database
	$msg = str_replace (&quot;&#039;&quot;, &quot;&#039;&#039;&quot;, $msg);
	$bdd-&gt;exec (&quot;insert into Mailbox( user, folder, message, senttime ) values ( &#039;toto&#039;, &#039;Sent&#039;, &#039;$msg&#039;, $FCT_CURRENT_TIME&quot;);
</pre>
<p><a name="Advices"></a>
<h2>Advices</h2>
<p><a name="Send+a+mail+in+HTML+format"></a>
<h3>Send a mail in HTML format</h3>
<p>Fist point: I personally hate receiving HTML mails: I *don't* recommend to 
  use it. 
<p>To send a HTML mail with libMail, you must attach your HTML source as a file: 
<p> 
<pre>	$file = &quot;mail.html&quot;;
	$mail-&gt;Body (&quot;This mail is formatted in HTML - shame on me&quot;);
	// inline intructs the mail client to display the HTML if it can
	$mail-&gt;Attach ($file, &quot;text/html&quot;, &quot;inline&quot;);
</pre>
If your HTML page contains some images or links don't forget either to : 
<p>
<ul>
  <li> rewrite them in absolute : /mahomepage.html becomes http://chez.moi.com/mahomepage.html 
  </li>
  <li> define a <b>BASE HREF</b> in the HEAD section. All relative links will 
    be relative to this URL </li>
  <pre>	&lt;head&gt;
		&lt;base href=&quot;http://chez.moi.com/&quot;&gt;
	&lt;/head&gt;
</pre>
  <li> When your recipients don't have any web access, you have a few solutions 
    left such as the <b>data:</b> URLs that i describe <a href="http://lwest.free.fr/doc/php/smp/?docid=data_url">here 
    (french)</a> or the linked parts that i should document soon. </li>
  <p>
</ul>
<p>
<p>
<p>
<p><a name="Statut"></a>
<h2>Status</h2>
<p>
<table >
  <tr>
    <td>Name</td>
    <td>libmail</td>
  </tr>
  <tr>
    <td>Lang</td>
    <td>php3 / php4</td>
  </tr>
  <tr>
    <td>Version</td>
    <td>1.4</td>
  </tr>
  <tr>
    <td>Lastmod</td>
    <td>Mon Jan 12 20:56:GMT 2004</td>
  </tr>
  <tr>
    <td>Authors</td>
    <td><a href="mailto:hide@address.com?subject=libmail">Leo West</a>, <a href="mailto:hide@address.com?subject=libmail">Setec Astronomy</a></td>
  </tr>
</table>
<p><a name="Summary"></a>
<h2>Summary</h2>
<p><a name="summary"></a><ol class=idx> 
<li><a href="#LIBMAIL" class=aIdx>LIBMAIL</a></li><ol class=idx>
<li><a href="#Description" class=aIdx>Description</a></li>
<li><a href="#ChangeLog" class=aIdx>ChangeLog</a></li>
<li><a href="#Synopsis" class=aIdx>Synopsis</a></li>
<li><a href="#Installation" class=aIdx>Installation</a></li>
<li><a href="#Documentation" class=aIdx>Documentation</a></li>
<ol class=idx>
  <li><a href="#Constructor" class=aIdx>Constructor</a></li>
  <li><a href="#Subject%28+string+sujet+%29" class=aIdx>Subject ([string subject])</a></li>
  <li><a href="#From%28+address+%29" class=aIdx>From (string from_email, [string 
    from_name])</a></li>
  <li><a href="#To%28+mixed+address+%29" class=aIdx>To (mixed address)</a></li>
  <li><a href="#CC%28+mixed+address+%29" class=aIdx>CC (mixed address)</a></li>
  <li><a href="#BCC%28+mixed+address+%29" class=aIdx>BCC (mixed address)</a></li>
  <li><a href="#Body%28+string+body%2C+%5Bstring+charset%5D+%29" class=aIdx>Body 
    ([string body], [string charset] )</a></li>
  <li><a href="#Attach%28+string+filename%2C+%5Bstring+mimetype%5D%2C+%5Bstring+disposition%5D+%29" class=aIdx>Attach 
    (string filepath, [string mimetype], [string disposition], [string filename])</a></li>
  <li><a href="#Organization%28+string+%24org+%29" class=aIdx>Organization (string 
    $org)</a></li>
  <li><a href="#ReplyTo%28+string+address+%29" class=aIdx>ReplyTo (string replyto_email, 
    [string replyto_name])</a></li>
  <li><a href="#ReplyTo%28+string+address+%29" class=aIdx>ReturnPath (string returnpath_email, [string returnpath_name])</a></li>
  <li><a href="#Priority%28+integer+%24priority+%29" class=aIdx>Priority ([integer 
    $priority])</a></li>
  <li><a href="#Receipt%28%29" class=aIdx>Receipt ()</a></li>
  <li><a href="#Send%28%29" class=aIdx>Send ()</a></li>
  <li><a href="#Get%28%29" class=aIdx>Get ()</a></li>
</ol>
<li><a href="#Advices" class=aIdx>Advices</a></li>
<ol class=idx>
  <li><a href="#Send+a+mail+in+HTML+format" class=aIdx>Send a mail in HTML format</a></li>
</ol>
<li><a href="#Statut" class=aIdx>Statut</a></li>
<li><a href="#Summary" class=aIdx>Summary</a></li>
<p>
<p>
</body>
</html>
Return current item: libMail