Wednesday 29 May 2013

Sending Mails with attachment in Php

In php, their may arise situations where you have to send mails with attachments. So here Iam explaining how  sending mail through php library called Phpmailer.

Download phpmailer lib file from here.

Now place the below code:-

-
$msg="Thank you for your interest in our products. Your order details is attached with this mail.";


require_once 'class.phpmailer.php';

//$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

$admin="name";
$emailfrom=$adminemail;
$email_to=$receivermail;

$email =new PHPMailer(true);
$email->From      = $adminemail;
$email->FromName  = 'name';
$email->Subject   = 'your subject';
$email->Body      = $msg;
$email->AddAddress($orderdet[0]['email'] );

$file_to_attach = 'attachment.pdf';

$email->AddAttachment($file_to_attach, 'attachment.pdf' );

 $email->Send();


You can add any number of attachments by using code
$mail->AddAttachment('filepath');

Upload it on your server & check..................

No comments:

Post a Comment