Example :
<?php // Including PHP Mailer Library require_once('PHPMailer-master/class.phpmailer.php'); function smtpmailer($to, $from, $from_name, $sub, $msg) { $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Host = "smtp.example.com"; // specify main server $mail->Port = 25; // SMTP Port $mail->Username = "username"; // SMTP username $mail->Password = "password"; // SMTP password $mail->IsHTML(true); // set email format to HTML $mail->AddAddress($to); $mail->From = $from; $mail->FromName = $from_name; $mail->Subject = $sub; $mail->Body = $msg; $mail->AddReplyTo($from, $from_name); $mail->addCC("cc1@example.com"); $mail->addCC("cc2@example.com"); $mail->addBCC("bcc1@example.com"); $mail->addBCC("bcc2@example.com"); $mail->AddAttachment("test.pdf"); // add attachment if(!$mail->Send()) { return "Sorry, Unable to send mail..." . $mail->ErrorInfo; } else { return "Mail sent Successfully..."; } } $to = "receiver@example.com"; $from = "sender@example.com"; $from_name = "Sender"; $sub = "Reg: Test Mail"; $msg = "Dear User,
This is a test mail from CodePHPOnline."; echo smtpmailer($to, $from, $from_name, $sub, $msg); /* Output : Mail sent Successfully... */ ?>
Technical Architect
Kuala Lumpur, Malaysia
I'm a Full Stack Web Developer working in a MNC and passionate of developing modern web and mobile applications.
I have designed and developed CodephpOnline & CodephpOnline Wiki platform to expatiate my coding and technology learning experiences.
In my leisure time, I write technical articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Linux, Angular, Ionic, ReactJS, NodeJS, AJAX, jQuery, Cloud and more.