Sending mail using PHP

Sending mail using PHP

Sending Mail using PHP

Sending mail using PHP is easy, only if you know the basics, First of all you are going to be using Gmail SMTP to send the mails. (SMTP stands for Simple Mail Transfer Protocol)

Download PHP mailer Here

Insert the following files into your current directory

  • class.phpmailer.php
  • class.smtp.php

Make sure you have a Gmail Account and you are aware of the username and password

insert the code below to send email

$mail = new PHPMailer();
$mail->Port = 465;
$mail->Host = ""; // specify main and backup server
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = "yourpassword"; // SMTP password
$mail->From = "";//From Email to display
$mail->FromName = "Your Name";
$mail->AddAddress(""); // name is optional
$mail->AddReplyTo("", "Your Name");
$mail->WordWrap = 50; // optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "The Subject";
$message = "";
$mail->Body = $message;
$mail->AltBody = '';
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;

Note that if you are sending mail from localhost, you may need to enable SSL extension by un-commenting the ‘extension=php_openssl.dll’ in PHP ini, all you have to do is open the PHP ini file, look for the ‘;extension=php_openssl.dll’ and delete the leading semi-colon, which will enable the extension

Also ensure you replace the default values with adequate values

Thank you for reading this post