Here By Reading this content you can easily send email using PHP.

Sending email messages are very common for a web application, for example, sending welcome email when a user create an account on your website, sending newsletters to your registered users, or getting user feedback or comment through website’s contact form, and so on.

You can use the PHP built-in mail() function for creating and sending email messages to one or more recipients dynamically from your PHP application either in a plain-text form or formatted HTML.

The basic Syntax of this function given here:

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

The following block summarizes the parameters of this function.

to : Required. Specifies the receiver / receivers of the email
subject : Required. Specifies the subject of the email.
message : Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters.
headers : Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).
parameters : Used to pass additional parameters.

Send Plaintext Emails

The simplest way to send an email with PHP is to send a text email. In the example below we first declare the variables — recipient’s email address, subject line and message body — then we pass these variables to the mail() function to send the email.


$to = ‘[email protected]’;
$subject = ‘Job Regarding’;
$message = ‘Hi test, Ary you want to do job at Futurelens?’;
$from = ‘[email protected]’;

// Sending email
if(mail($to, $subject, $message)){
echo ‘success’;
} else{
echo ‘fail’;
}

Send Html Formatted Emails

When you send a text message using PHP, all the content will be treated as simple text. If you want to improve that output, then make the email into a HTML-formatted email.

To send an HTML email, the process will be the same. However, this time we need to provide additional headers as well as an HTML formatted message.


$to = ‘[email protected]’;
$subject = ‘Job Regarding’;
$from = ‘[email protected]’;

// To send HTML mail, the Content-type header must be set

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;

// Create email headers

$headers .= ‘From: ‘.$from.”\r\n”.
‘Reply-To: ‘.$from.”\r\n” .
‘X-Mailer: PHP/’ . phpversion();

// Compose a simple HTML email message..Here you can also use HTML tags for make good looking content.

$message = ”;
$message .= ‘Hi Test’;
$message .= ‘

Are you want to do jo at futurelens?’;
$message .= ”;

// Sending email
if(mail($to, $subject, $message, $headers))
{
echo ‘Success’;
}
else
{
echo ‘Fail’;
}

With use of this code and content you can send mail using php easily.

So this is a topic of the mail sending Using PHP. For more get in touch with us at [email protected]