email sendingIn this tutorial Sending plain text email using PHP. PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient’s email address, the subject of the the message and the actual message additionally there are other two optional parameters.

mail( to, subject, message, headers, parameters );

Here is the description for each parameters.

Parameter Description
to Required. Specifies the receiver / receivers of the email
subject Required. Specifies the subject of the email. This parameter cannot contain any newline characters
message Required. Defines the message to be sent. Each line should be separated with a LF (n). Lines should not exceed 70 characters
headers Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (rn)
parameters Optional. Specifies an additional parameter to the sendmail program

As soon as the mail function is called PHP will attempt to send the email then it will return true if successful or false if it is failed.

Multiple recipients can be specified as the first argument to the mail() function in a comma separated list.

Example:

Following example will send an HTML email message to [email protected] You can code this program in such a way that it should receive all content from the user and then it should send an email.

<html>
<head>
<title>Sending email using PHP</title>
</head>
<body>
<?php
   $to = "[email protected]";
   $subject = "This is subject";
   $message = "This is simple text message.";
   $header = "From:[email protected] rn";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true )
   {
      echo "Message sent successfully... thanks to http://latest-tutorial.com";
   }
   else
   {
      echo "Message could not be sent... contact http://zeeshanakhter.com";
   }
?>
</body>
</html>

Sending plain text email using PHP

Sending HTML email using PHP

Sending attachments with email using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *