Adding details in body mail in php

In PHP, you can add details to a body of an email using the mail() function or a PHP mail library such as PHPMailer. Here are some examples:

Using the mail() function

<?php
$to = '[email protected]';
$subject = 'Test email';
$body = 'This is the body of the email.';

// Add additional details to the body
$body.= "\r\n";
$body.= 'Name: John Doe';
$body.= "\r\n";
$body.= 'Email: [email protected]';
$body.= "\r\n";
$body.= 'Phone: 123-456-7890';

// Send the email
mail($to, $subject, $body);
?>

In this example, we're adding three lines of text to the body of the email using the . operator to concatenate the strings.

Using PHPMailer

<?php
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';

$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'your_password';

$mail->setFrom('[email protected]', 'Your Name');
$mail->addAddress('[email protected]');

$mail->Subject = 'Test email';
$mail->Body = 'This is the body of the email.';

// Add additional details to the body
$mail->Body.= '<br>';
$mail->Body.= 'Name: John Doe';
$mail->Body.= '<br>';
$mail->Body.= 'Email: [email protected]';
$mail->Body.= '<br>';
$mail->Body.= 'Phone: 123-456-7890';

$mail->send();
?>

In this example, we're using the PHPMailer library to send an email. We're adding the additional details to the body of the email using the Body property and concatenating the strings using the . operator.

Using HTML email

<?php
$to = '[email protected]';
$subject = 'Test email';
$body = '<html><body>';
$body.= 'This is the body of the email.';
$body.= '<p>Name: John Doe</p>';
$body.= '<p>Email: [email protected]</p>';
$body.= '<p>Phone: 123-456-7890</p>';
$body.= '</body></html>';

// Send the email
mail($to, $subject, $body, 'text/html');
?>

In this example, we're using HTML to format the email body. We're adding the additional details using HTML tags (<p>) and concatenating the strings using the . operator. We're also specifying the text/html content type to indicate that the email body is in HTML format.

Note that in all examples, you should replace the placeholders ($to, $subject, $body, etc.) with your actual email settings and data.