Answers for "send html mail using php"


php send email

// use this library ->

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function sendEmail(){
  	require 'phpmailer/vendor/autoload.php';	

    //Create an instance; passing `true` enables exceptions
    $mail = new PHPMailer(true);
    $mail->CharSet = 'UTF-8';
  try {
      $receiver = '[email protected]';
      $name = 'Name';

      //Server settings
      $mail->SMTPDebug = 1;                      //Enable verbose debug output
      $mail->isSMTP();                                            //Send using SMTP
      $mail->Host       = 'tls://';                     //Set the SMTP server to send through
      $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
      $mail->Username   = '[email protected]';                     //SMTP username
      $mail->Password   = 'PASSWORD';                               //SMTP password
      $mail->SMTPSecure = tls;            //Enable implicit TLS encryption
      $mail->Port       = 587;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

      $mail->From = '[email protected]';
      $mail->setFrom('[email protected]', 'Name');
      $mail->addAddress($receiver, $name);     //Add a recipient

      $mail->isHTML(true);                                  //Set email format to HTML
      $mail->Subject = 'Subject';
      $mail->Body    = 'Body';

      echo 'Message has been sent';
  } catch (Exception $e) {
      echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
Posted by: Guest on July-23-2021

php mail example

$message = '
  <title>Review Request Reminder</title>
  <p>Here are the cases requiring your review in December:</p>
      <th>Case title</th><th>Category</th><th>Status</th><th>Due date</th>
      <td>Case 1</td><td>Development</td><td>pending</td><td>Dec-20</td>
      <td>Case 1</td><td>DevOps</td><td>pending</td><td>Dec-21</td>
Posted by: Guest on October-22-2020

Browse Popular Code Answers by Language