I would like to send emails from my PHP program. Is it possible? I think we need to use PHP mail function but don't how and where to use it. Can any one help me or just provide me the syntax with a basic idea of how to use it?
I would like to send emails from my PHP program. Is it possible? I think we need to use PHP mail function but don't how and where to use it. Can any one help me or just provide me the syntax with a basic idea of how to use it?
Here is an example of how to use PHP mail function:
PHP Code:
<?php
$to = "abc@site.com";
$subject = "Hello World!";
$body = "Welcome to PHP mail function.";
$headers = "From: pqr@mysite.com \n" .
$sent = mail ($to, $subject, $body, $headers);
if ($sent)
{
echo "Thank you!";
}
else
{
echo 'Failed';
}
?>
PHP mail () function
Syntax:
bool mail (string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]])
Parameters
- to: Receiver, or receivers of the mail.
- subject: Subject of the email to be sent.
- message: Message to be sent. [Each line should be separated with a LF (\n). Lines should not be larger than 70 characters.]
- additional_headers (optional): String to be inserted at the end of the email header. [This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).]
- additional_parameters (optional): The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting.
Bookmarks