Tuesday, March 27, 2012

HTML object

html object

HTML object

In the early days of www, HTML pages are displayed as text. Then came the pictures, thus enhance the presentation site. But now, we can include many more objects than pictures: sounds, Java applets, video clips, Flash animations ... Almost anything is possible. Almost all? And yes, because in this area, browsers do not do as they please. It seems that the W3C WARRANTY were not all followed in their entirety. To include an item in a page, use the tag like <OBJECT> container. The following example is intended to display an image the same way with the tag <IMG> . It is quite another ...



 <OBJECT Data="../../images/abc.gif" type="image/gif" width="520" height="95">
 Since browsers are almost ALL incomptétents with
 this tag, you should see this text
 </ OBJECT>
Since browsers are almost ALL incomptétents with this tag, you should see this text If you are running Netscape Navigator, you certainly do not see anything. If you're running Microsoft Internet Explorer, you normally distinguish a kind of image in a <IFRAME> . Luckily he left <IMG> . Detail but rather the code. The HTML content in the tag <OBJECT> is intended to be displayed if the browser be unable to use the object. The data attribute represents the URL of the resource to use. Type corespond to the MIME type. MIME means Multipurpose Internet Mail Extensions. This lets the browser know what type of object: if a picture, video, sound ... In our case, it is a picture gif . See the following table to know the MIME type to use depending on the subject to include:
MIME types
MIME type File type
application / excel Microsoft Excel Document
application / msword Microsoft Word document
application / pdf Acrobat Reader file
application / rtf RTF document
application / zip ZIP
audio / midi Audio MIDI file
audio / mpeg MP3 Audio File Type
audio / x-aiff AIFF audio file
audio / x-pn-realaudio RealAudio sound file
image / bmp Bitmap Image
image / jpeg JPEG image
image / png PNG
image / tiff TIFF image
multipart / x-zip Archive
text / html HTML document
text / plain Plain Text
video / mpeg MPEG video
video / quicktime QuickTime Video
video / x-msvideo AVI video type
video / x-sgi-movie Video type MOVIE
This table is of course far from complete. It NCLUSION however the most common types. It may thus include a large number of media, such as clips or sounds: just know the appropriate MIME type. The width and height attributes specify the dimensions that must occupy the object, in pixels. Here are the other possible attributes:
  • align defines the horizontal or vertical alignment of the object. Values ​​can be left, center or right to the horizontal, or top, middle or bottom for vertical.
  • standby displays a text during loading of the object.
  • code specifies the URL of a class for Java applets.
To include an applet in a page, you can use the tag <OBJECT> instead of the tag <APPLET> :
 <OBJECT Code="NervousText.class" width="180" height="60">
 <PARAM Name="text" value="Cyb Warrior">
 </ OBJECT>
The <PARAM> tag is not limited only to the applet. It allows to pass parameters to the object and is also used with Flash animations. The tag <PARAM> can take the following attributes:
  • name defines the parameter name. In our example, text
  • value is the value of this parameter. Here is Cyb Warrior
  • valuetype defines the type of the value of value. It can take two values:
    • data: this is the default (which is why we have deliberately omitted in our example). The value is treated as a given.
    • ref: The value then points to an outside resource (in the case of an image, for example).

mail php :Send an email with PHP

mail php

mail php Introduction to PHP mail ()


This is an application that is recurring on our forum, and the part of novice users with PHP in general: how can we send an email from a web page in PHP?

This is what we will see in this tutorial, I'll split it into two parts:
- Send an email with mail () native PHP (for beginners)
- Send email with Zend Framework (OOP)

php mail Explanations

1. Send email in text format

To send a basic email in PHP is simple, just use the mail () function.
Parameter, it takes respectively the recipient, subject, message, and (optionally) the headers.
The easiest way to email text is as follows:
$message = "Hello World"; mail('destinataire@example.com', 'Mon Sujet', $message);
It is very simple, but somewhat limited in this way. Indeed, you do not specify the sender, can not specify the person to place a copy (to send an email to several people), etc..

With additional headers that you can pass in the fourth parameter, you will be able to customize things a little. Here are some commonly used headers:

$headers ='From: "mon nom"<expediteur@example.com>' . "\n "; $headers .='To: Mary 
<mary@example.com>, Kelly <kelly@example.com>' . "\n"; $headers .='Cc: 
anniversaire_archive@example.com' . "\n"; $headers .=' Bcc: 
anniversaire_verif@example.com' . "\n"; $headers .=' Reply-To: 
adresse_de_reponse@example.com' . "\n"; $headers  .='MIME-Version: 1.0' . "\n"; 
$headers .='Content-Type: text/plain; charset="iso-8859-1"' . "\n"; $headers .='
 Content-Transfer-Encoding: 8bit'; $message = "Hello World"; mail
('destinataire@example.com', ' Mon Sujet', $message, $headers);

Notice that all headers are concatenated (end to end with. "="), And it takes place a newline at the end of each header, where the character "n" at the end of each of them.

Warning: I put "\ n" for line breaks, but if it does not work for you, you can try replacing the "\ n" with "\ rn", because it depends on the mail servers.

I will now detail the usefulness of these headers (not exhaustive, there are others):
  • From: the name and email address of the sender
  • To: Name and address of one or more recipients (extra, for as we have seen, we can already specify a recipient in the first parameter of the mail)
  • Cc: other recipients who will receive the mail in "Carbon Copy". They will be able to see and copy that to the message was transmitted.
  • Bcc: ADDRESSEES others who will receive the mail in "Blind Carbon Copy". They will copy but will not be able to see that the message has been transmitted, it is a blind copy.
  • Reply-To: Specifies an email address different from the response sender address, if you want the answer you in a different address.
  • MIME-Version: the version of the mime type used
  • Content-type: to specify the mime type of mail and charset (character set). Often you will use "text / plain" as the type for an email in text format, and "text / html" for an email in html format (we'll see below).
  • Content-Transfer-Encoding: This header specifies the encoding of the mail or any part thereof (for sending a text + html for example). It can for example take the values ​​7 and 8 bit (7 bit encoding is used in English speaking countries who do not need to manage accented letters)

2. Send email as HTML

We've already done the heavy lifting in the previous paragraph, because there is not much to change in order to send an email in html format.
Suffice it to change the "Content-type" like this:
$headers .='Content-Type: text/html; charset="iso-8859-1" ' . "\n";
It's left to do, of course, modify the message body to insert HTML code.
An example of sending mail in html with PHP, in this example I will place the logo 6ma.fr early message, and to insert an image, it is mandatory to use the HTML format.

$headers ='From: "mon nom"<expediteur@example.com>' . "\ n"; $headers .='To: Mary 
<mary@example.com>, Kelly <kelly@example.com>' . "\n"; $headers .='Cc: 
anniversaire_archive@example.com' . "\n"; $headers .='Bcc: 
anniversaire_verif@example.com' . "\n"; $headers .=' Reply-To: 
adresse_de_reponse@example.com' . "\n"; $headers  .='MIME-Version: 1.0' . "\n"; $
headers .='Content-Type: text/html; charset="iso-8859-1"' . "\n"; $headers .=' 
Content-Transfer-Encoding: 8bit'; $message = "<html><head> <title>Mon titre
</title></head>"; $message .= "<body> <img src='http://www.6ma.fr/image/bannieres 
/6ma-181x72.png' /> <br /><br /> Hello World</body> </html>"; mail
('destinataire@example.com', 'Mon Sujet', $message, $headers);
 
Compared to sending email in text format, so I just changed the "Content-Type" header in the mail, and the message body stored in the variable $ message.
In the body, place the html code classic, as you would for a web page in html.

Here in the email that is sent, we will have the logo 6ma.fr, two line breaks, and below the text "Hello World".

III. Conclusion of the tutorial


Here, we have just seen how to send an email with PHP, whether simple text format or html format which allows you to insert more things: images, links, etc..

However, it remains to see opportunities for more advanced, you say:
- How to send an email in plain text + html combination? (So ​​that someone who can not read html, still sees the message in text format)
- How to send an attachment?

mail php

In the following tutorial, we'll see how to achieve all this by introducing parallel sending emails with the Zend Framework.