Send Mail using PHP
The mail()
function used to send an email in PHP.
Syntax :
<?php mail(to,subject,message,headers,parameters); ?>
Parameter | Description |
---|---|
to (Required) | Receivers of the email |
subject (Required) | Subject of the email |
message (Required) | Message to be Send. Lines should not be more than 70 characters. Each line should be separated with CRLF(\r\n). Note(Windows Only): Replace Single dot with double dot. Because if a single dot found on the beginning of a line, it is removed. <?php $txt_msg=str_replace("\n.","\n..",$txt_msg); ?> |
headers (Optional) | It's used to add extra headers like From, Cc and Bcc. |
parameters (optional) | Specifies an additional parameter to the sendmail program. |
The following example shows, how to send email using PHP mail()
function.
Example :
<?php $to = "someone@example.com"; $subject = "Mail with PHP"; $message = "<h1>Simple Mail.</h1>"; $message .= "<h1>This is HTML message.</h1>"; $header="From:user@domain.in"."\r\n"; $header.="X-Mailer:PHP/".phpversion()."\r\n"; $header.="Content-type:text/html; charset=iso-8859-1"; $response=mail($to,$subject,$message,$header); if($response==true){ echo "Mail send Successfully"; }else{ echo "Mail send Failed!!!"; } ?>