To Send Mail to User from SMTP using PHPMailer Library with Attachments:
PHPMailer is a powerful library for sending email from PHP. For sending e-mail, you have to first download PHPMailer library from GitHub and include it in your code snippet below:

Example :

   	// Including PHP Mailer Library

	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 = "";  // 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->From = $from;
        $mail->FromName = $from_name;
		$mail->Subject = $sub;
		$mail->Body = $msg;
        $mail->AddReplyTo($from, $from_name);
        $mail->AddAttachment("test.pdf");  // add attachment
            return "Sorry, Unable to send mail..." . $mail->ErrorInfo;
            return "Mail sent Successfully...";
	$to = "";
	$from = "";
    $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... */ ?>
Rahul Yadav

Technical Architect

Kuala Lumpur, Malaysia

Connect Me:     

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, technical and digital learning experiences.

In my leisure time, I write articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Magento, Linux, Angular, Ionic, ReactJS, NodeJS, Cloud and more.

Tag Cloud