mail php function to gmail code example

Example 1: php mail function

<?php
$to = $_POST['email'];
$subject = "Email Subject";

$message = 'Dear '.$_POST['name'].',<br>';
$message .= "We welcome you to be part of family<br><br>";
$message .= "Regards,<br>";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

mail($to,$subject,$message,$headers);
?>

Example 2: php mail example

$message = '
<html>
<head>
  <title>Review Request Reminder</title>
</head>
<body>
  <p>Here are the cases requiring your review in December:</p>
  <table>
    <tr>
      <th>Case title</th><th>Category</th><th>Status</th><th>Due date</th>
    </tr>
    <tr>
      <td>Case 1</td><td>Development</td><td>pending</td><td>Dec-20</td>
    </tr>
    <tr>
      <td>Case 1</td><td>DevOps</td><td>pending</td><td>Dec-21</td>
    </tr>
  </table>
</body>
</html>
';

Example 3: send mail config using gmail php

Before sending emails using the Gmails SMTP Server, you to make some of the
  security and permission level settings under your Google Account Security
  Settings.

1. Make sure that 2-Step-Verification is disabled.

2. Turn ON the "Less Secure App" access or click here.

3. If 2-step-verification is enabled, then you will have to create app
  password for your application or device.

4. For security measures, Google may require you to complete this additional
    step while signing-in. Click here to allow access to your Google account
      using the new device/app.

Note*: It may take an hour or more to reflect any security changes
===================================================================
PHP CODE CONFIG :=
  
$mail->SMTPDebug  = 1;  
$mail->SMTPAuth   = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port       = 587;
$mail->Host       = "smtp.gmail.com";
$mail->Username   = "[email protected]";
$mail->Password   = "your-gmail-password";

=================================================================

For More Info check this link : https://pepipost.com/tutorials/send-an-email-via-gmail-smtp-server-using-php/

Tags:

Php Example