Sending Email using PHPMailer: Before starting, you need to do the following steps
- Download https://github.com/PHPMailer/PHPMailer
- PHP page with below code
Create email.php & copy the downloaded PHPMailer source code into htdocs or in your project directory & in your project directory which will look like below.
edit email.php file and paste below code
<?php require 'PHPMailer-master/PHPMailerAutoload.php'; $email="test@domain.com";// $mail = new PHPMailer(); $mail->SMTPDebug = 0; $mail->isSMTP(); // Set mailer to use SMTP $mail->SMTPAuth = true; // Enable SMTP authentication $mail->SMTPSecure = 'tls'; //$mail->SMTPSecure = 'ssl'; $mail->Host = 'smtp.mail.com'; // Enable encryption, 'ssl' also accepted // Specify main and backup server $mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS //$mail->Port = 465; $mail->Username = 'sender email address'; // SMTP username $mail->Password = 'sender password'; $mail->setFrom('Sender email', 'Set alias name'); //Set who the message is to be sent from $mail->addAddress('to address email here', 'name is optional'); // Add a recipient //$mail->addCC('cc@example.com'); $mail->addBCC('adding receipents in BCC '); $mail->WordWrap = 50; // Set word wrap to 50 characters //$mail->addAttachment('adding attachment file path'); // Add attachments $mail->isHTML(true); // Set email format to HTML $mail->Subject = "Test email"; $mail->Body = "welcome test email body from PHP"; //Read an HTML message body from an external file, convert referenced images to embedded, //convert HTML into a basic plain-text alternative body $mail->msgHTML("creating html message"); if(!$mail->send()) { echo 'Message could not be sent.'; exit; } echo "your email has sent successfully"; ?></pre>
Save the file and try to access http://localhost:serverportnumber/email.php
Also Read: Sending Email from Godaddy Server
Sending Email using PHPMailer