An SMTP server is a machine that takes care of the whole email delivery process: that's why to send your messages with an email client or software you need first of all to configure the correct SMTP settings.
We are going to use PHPMailer class for sending emails. It’s an easily usable PHP library for sending emails. This class is included in the Download File.
Download PHPMailer form the below link
https://github.com/PHPMailer/PHPMailer
Create a new file send.php and place the following code into it as per the instructions.
Include PHPMailer class first
include("phpmailer/class.phpmailer.php");
configuration
This configuration contains account information, Recipient address with name and the message details.
$account="yourmailid@outlook.com";
$password="yourpassword";
$to="receivermailid@outlook.com";
$from="sendermailid@outlook.com";
$from_name="yourname";
$msg="<strong>This is the test message</strong>";
$subject="Test message";
$password="yourpassword";
$to="receivermailid@outlook.com";
$from="sendermailid@outlook.com";
$from_name="yourname";
$msg="<strong>This is the test message</strong>";
$subject="Test message";
Create the Class object and append the settings of the SMTP server
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.live.com";
$mail->SMTPAuth= true;
$mail->Port = 587;
$mail->Username= $account;
$mail->Password= $password;
$mail->SMTPSecure = 'tls';
$mail->From = $from;
$mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->addAddress($to);
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.live.com";
$mail->SMTPAuth= true;
$mail->Port = 587;
$mail->Username= $account;
$mail->Password= $password;
$mail->SMTPSecure = 'tls';
$mail->From = $from;
$mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->addAddress($to);
Error check
Then, check if the mail sends without any errors. If there is an error, it will print out the error
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "E-Mail has been sent";
}
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "E-Mail has been sent";
}
If there is any problem or error you are getting on this, please comment below we will try to help.