Top Ad unit 728 × 90

ticker

How To Sending Plain Text Email In PHP



How To Sending Plain Text Email In PHP



Sending plain text email:



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 (\r\n)
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 xyz@somedomain.com. 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 = "xyz@somedomain.com";
   $subject = "This is subject";
   $message = "This is simple text message.";
   $header = "From:abc@somedomain.com \r\n";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true )  
   {
      echo "Message sent successfully...";
   }
   else
   {
      echo "Message could not be sent...";
   }
?>
</body>
</html>


How To Sending Plain Text Email In PHP Reviewed by Rajat Jha on 09:19:00 Rating: 5

1 comment:

All Rights Reserved by INFO PHP 99 © 2014 - 2015
Powered by Blogger, Designed by Sweetheme

Contact Form

Name

Email *

Message *

Powered by Blogger.