All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

PHP Email Sending

All th process to send emails is very easy with the help of PHP.It uses mail() function to send emails.


Syntax


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

Code Explanation

  • to the value of to is the email address of the reciever.

  • subject the value of subject is the subject of the email.

  • message the value of message is the main content of the email.

  • header It is optional the value of header like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).

  • parameters It is optional specifies an additional parameter to the sendmail program.


Simple Example To send emails


<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>
❮ PrevNext ❯