Father
Professional
- Messages
- 2,601
- Reaction score
- 834
- Points
- 113
⛏ Requirements:
=> Editor
=> SMTP Logins
=> PHP Mailer
First of all, we need to write <?php which is the beginning of php file.
Now we have to get the PHP Mailer class from github. For that navigate to a directory and type:
Before we actually begin, we include the phpmailer:
We need to declare the PHP Mailer, and some variables which are used for the SMTP setup.
In most cases your SMTP format will be:
Well, let's use the $mail variable for setup:
setFrom will define the sender name, like no-replay@mail.com or Support one. Is also added two // which are comments to help you a bit. If you have SSL you can write also:
As you saw already the basic mail variable, we come now to the other stuff like budy, subject etc.
Well we setuped here some headers, i hope you understand my comments, if you copy & paste then you can see this better than in Telegram.
As you can see "Letter.html" means, you have to put a filename which contains the lettertext. (i used letter.html)
The last one with the if statement will give you an "output" if the mail was sent or not. => [»] Sent E-Mail Successfully output means it has been sent. You can customize all.
=> Editor
=> SMTP Logins
=> PHP Mailer
First of all, we need to write <?php which is the beginning of php file.
Now we have to get the PHP Mailer class from github. For that navigate to a directory and type:
Code:
composer require phpmailer/phpmailer
Before we actually begin, we include the phpmailer:
Code:
include "vendor/autoload.php";
use
PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
We need to declare the PHP Mailer, and some variables which are used for the SMTP setup.
In most cases your SMTP format will be:
Code:
smtp.mail.com|587|test.php@mail.com|top_secret
smtp.mail.com|465(SSL)|test.php@mail.com|top_secret
server|port|username&email|password|
Well, let's use the $mail variable for setup:
Code:
$mail = new PHPMailer(true);
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP Authentication
$mail->Host = 'smtp.gmail.com'; // SMTP Host
$mail->Port = 587; // SMTP Port
$mail->SMTPSecure = 'tls'; // Enable TLS Security
$mail->Username = 'test.php@mail.com'; // SMTP Username
$mail->Password = "top_secret"; // SMTP Password
$mail->From = 'test.php@mail.com'; // Mail come from (Username)
$mail->FromName = 'Support';
$email="someone@mail.com"; // Recipient's Email ID
$mail->IsHTML(true); // send as HTML
setFrom will define the sender name, like no-replay@mail.com or Support one. Is also added two // which are comments to help you a bit. If you have SSL you can write also:
Code:
$mail = "ssl://smtp.mail.com"
As you saw already the basic mail variable, we come now to the other stuff like budy, subject etc.
Code:
$from = $mail->From; // From name
$to = $email; // Recipients Email from $email variable
$mail->addAddress($to);
$mail->IsSendmail(); // Telling the class to use SendMail transport
$headers = "From: <".$from.">n"; // Adding the header From, and the email variable
$headers .= "X-Sender: yourname<".$from.">n"; // edit "yourname" with a supporter name or whatever, just define sender
$headers .= "X-Mailer: PHPn"; // mailer
$headers .= "X-Priority: 1n"; // Urgent message priority
$headers .= "Return-Path: ".$from."n"; // Return path for errors
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=iso-8859-1n"; // Mime type
Well we setuped here some headers, i hope you understand my comments, if you copy & paste then you can see this better than in Telegram.
Code:
$mailBody = "\n"; // just a neew line "\n"
$mailBody = file_get_contents('Letter.html');
As you can see "Letter.html" means, you have to put a filename which contains the lettertext. (i used letter.html)
Code:
mail->Subject = "Important Mail"; // Write Your Subject
$mail->MsgHTML($mailBody); // MSG HTML Body
$from = "no-reply@chase.com"; // Custom Domain from where the "mail" comes.
if($mail->Send()){
echo("\033[32m[»] \033[37mSent E-Mail Successfully To : \033[34m${to}");
}
else
{
echo("\033[31m[x] \033[37mE-Mail Not Sent Successfully [\033[34m${to}\033[37m]");
}
The last one with the if statement will give you an "output" if the mail was sent or not. => [»] Sent E-Mail Successfully output means it has been sent. You can customize all.
