How to send mail in PHP ?

Last updated 2 years, 4 months ago | 459 views 75     5

Tags:- PHP

Send mail in PHP

The mail() function allows you to send emails directly from a script.

mail(to,subject,message,headers,parameters);
 

Description of parameters

to Required. Specifies the receiver's email id
subject

Required. Specifies the subject of the email.

Note: This parameter cannot contain any newline characters

message

Required. Defines the message to be sent. Each line should be separated with an LF (\n). Lines should not exceed 70 characters.

Windows note: If a full stop is found at the beginning of a line in the message, it might be removed.  To solve this problem, replace the full stop with a double dot:

$txt = str_replace("\n.", "\n..", $txt);
headers Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).
parameters Optional. Specifies an additional parameter to the Sendmail program (the one defined in the sendmail_path configuration setting). (i.e. this can be used to set the envelope sender address when using Sendmail with the -f Sendmail option)
<?php

$to = "somebody@example.com";

$subject = "My subject";

$msg = "Hello world!";

$headers = "From: webmaster@example.com" . "\r\n" .

"CC: somebodyelse@example.com";

mail($to,$subject,$msg,$headers);

?>