PHP mail() Function Code to Send Emails Contact from a Form


PHP mail() Function Code to Send Emails Contact from a Form

The PHP mail() Function

User Sending all email messages is very important for a website applications, for examples: sending all emails a welcome email when a client created a new accounts on your websites or webpage, sending newsletters emails to your registered clients, or getting client feedback or comments through the website’s contact from..

Please can using the PHP code contact form with built-in mail() functions for creating and sending emails messages to one or many more recipients dynamically from your PHP code website application either in a plain-text forms or formatted HTML code.

The basic syntax of the mail() function can be given with:

mail (to,name,phone, subject, message, headers, parameters)

The following table summarizes the parameters of this function.

Required       =       The following parameters are required

To                   =       The recipient’s email address.

Name             =       this input client name required.

Phone             =      this input user phone number required.

Subject           =      Subject of the email to be sent. This parameter cannot contain any newline                                          characters.

Massage         =      Defines the message to be sent. Each line should be separated with a line                                            feed-LF (\n). Lines should not exceed70 characters.

Optional         =       The following parameters are optional

Headers          =       This is typically used to add extra headers such as “From”, “Cc”, “Bcc”. The                                             additional headers should beseparated with a carriage return plus a                                                      line feed-CRLF (\r\n).

parameters    =       Used to pass additional parameters

Sending Plain Text Emails

The simplest way to send an email with PHP is to send a text email. In this examples below we give php code web applications declared this variables — recipients emails address, subjects line and message body in web applications— then we passed these variables to this mail() functions to sending the emails.
PHP mail() Function Code


$to = "";
$subject = "Contact mail";
$headers = "From: $from";

echo "Email successfully sent.";

HTML Contact Form Code

<form id="emailForm" name="emailForm" method="post" action="" >
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1">
  <td colspan="2"><strong>Online Contact Form</strong></td>
  <td>Name :</td>
  <td><input name="name" type="text" id="email" required></td>
  <td>Phone :</td>
  <td><input name="Phone" type="text" id="email" required></td>
  <td>E-mail :</td>
  <td><input name="email" type="text" id="email" required></td>
  <td>Message :</td>
  <textarea name="msg" cols="45" rows="5" id="msg" required></textarea>
  <td><input name="SubmitBtn" type="submit" id="SubmitBtn" value="Submit"></td>

About the author

ashok123456 administrator