PHP Mail
ADVERTISEMENTS
PHP provides its own default mailing system, It uses the default mail server of hosting where are PHP is hosted.
Example-1
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>
Example-2
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Requirements
PHP must have access to the Sendmail binary on your system during compile time.
Installation
There is no installation needed to use these functions; they are part of the PHP core.
Runtime Configuration
The behavior of these functions is affected by settings in php.ini.
Mail configuration options
Name | Default | Changeable | Changelog |
---|---|---|---|
mail.add_x_header | "0" | PHP_INI_PERDIR | Available since PHP 5.3.0. |
mail.log | NULL | PHP_INI_PERDIR | Available since PHP 5.0.0. (PHP_INI_SYSTEM|PHP_INI_PERDIR) |
mail.force_extra_parameters | NULL | PHP_INI_PERDIR | Available since PHP 5.0.0. (PHP_INI_SYSTEM|PHP_INI_PERDIR) |
SMTP | "localhost" | PHP_INI_ALL | |
smtp_port | "25" | PHP_INI_ALL | |
sendmail_from | NULL | PHP_INI_ALL | |
sendmail_path | "/usr/sbin/sendmail -t -i" | PHP_INI_SYSTEM |
Resource Types
This extension has no resource types defined.
Predefined Constants
This extension has no constants defined.
Mail Functions
- ezmlm_hash — Calculate the hash value needed by EZMLM
- mail — Send mail