php mail function gmail code example
Example 1: php mail function
<?php
$to = "[email protected]";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$number = $_POST['number'];
$cmessage = $_POST['message'];
$headers = "From: $from";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "You have a message from your Bitmap Photography.";
$logo = 'img/logo.png';
$link = '#';
$body = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Express Mail</title></head><body>";
$body .= "<table style='width: 100%;'>";
$body .= "<thead style='text-align: center;'><tr><td style='border:none;' colspan='2'>";
$body .= "<a href='{$link}'><img src='{$logo}' alt=''></a><br><br>";
$body .= "</td></tr></thead><tbody><tr>";
$body .= "<td style='border:none;'><strong>Name:</strong> {$name}</td>";
$body .= "<td style='border:none;'><strong>Email:</strong> {$from}</td>";
$body .= "</tr>";
$body .= "<tr><td style='border:none;'><strong>Subject:</strong> {$csubject}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td colspan='2' style='border:none;'>{$cmessage}</td></tr>";
$body .= "</tbody></table>";
$body .= "</body></html>";
$send = mail($to, $subject, $body, $headers);
?>
Example 2: 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: