PHP - E-mail With PHP

E-mail With PHP.

PHP uses its inbuilt mail() function to send emails from the script.


$to = "sample@";
$subject = " sample mail";
$message = “sample email message.";
$from = " sample1@";
$headers = "From: $from";
echo "Mail Sent.";

Header is an optional parameter that specifies any CC or BCC. The mail function requires a working email system. SMTP settings needs to be done in the .ini file.

E-mail With PHP.

PHP supports sending email through a form. First enter the to address, from address, subject, message fields from a simple html form. In the html file use the tag with action attribute assigned with the php file, which handles sending email.

<form method="post" action="mailContact.php">

Ensure that proper validation is done for mail form.

The script should take the data posted from the form- to mail id, from mail id, subject, message etc into corresponding variables, using $_REQUEST.

Use the function mail() as follows to send the mail to the destination address.
mail($to, $subject, $body, $headers);
PHP - How Sessions Work?
How Sessions Work? - When a user logs in an application, his details are usually stored in a session variable.....
PHP - PHP Superglobals
PHP Superglobals - These are predefined variables that are by default available globally..
PHP - What is the difference between mysql_connect() and mysql_pconnect()?
What is the difference between mysql_connect() and mysql_pconnect()? - When mysql_pconnect() is used, the function initially tries to find an open persistent connection....
Post your comment