sending authenticated smtp email with attachments using php

sending authenticated smtp email with attachments using php

In this post we will show you sending authenticated smtp email with attachments using php and smtp, hear for sending authenticated smtp email with attachments using php and smtp we will give you demo and example for implement.

We recently had to reconfigure how mail was being sent using PHP and oddly there were many sources out there that just didn’t seem to work. So here’s some sample code we put together that should work if you’re trying to send authenticated SMTP email with an attachment using Pear Mail.

code for sending authenticated smtp email with attachments using php and smtp

code for sending authenticated smtp email with attachments using php and smtp, hear we use for send one sample zip file you can also send image, txt or other format file.


require 'class.phpmailer.php';

$mail = new PHPMailer;

$user_name = "user name";
$source_file = "your_folder_name/potest.pdf";
$reanme_file = "reanmefile.pdf";

$user_email_id = "TO-EMAIL-ADDRSS@gmail.com";

$mailto = $user_email_id;

$subject = "Notification for purchase ONLINECODE";
$bodytext = "Hello<br> <b>".$user_name."</b>,<br>This Order has been sent to the user for their review. You will be notified when their review has been completed.<br>code for sending authenticated smtp email with attachments using php and smtp demo and example. <br>Regard <br> <b>ONLINECODE Team</b>  ";

$mail->IsSMTP();                                      // Set mailer to use SMTP
//$mail->SMTPSecure = 'tls';
$mail->Host = 'ssl://smtp.gmail.com';                // Specify main and backup server

$mail->Port = 465;
$mail->SMTPDebug = 1;                                  // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'YOUR-EMAIL@gmail.com';                // SMTP username
$mail->Password = 'ADD-MY-PASSWORD';                  // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
$mail->AddAttachment($source_file, $reanme_file);
$mail->From = 'YOUR-EMAIL@gmail.com';
$mail->FromName = 'ONLINECODE Team'; // add frome name
$mail->AddAddress($mailto , $user_name);  // Add a recipient  to name
//$mail->AddAddress($mailto );               // Name is optional

$mail->IsHTML(true);    // Set email format to HTML

$mail->Subject = $subject;
$mail->Body    = $bodytext;

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
else
{
echo 'Message has been sent';
}

Hope this code and post will helped you for implement code for sending authenticated smtp email with attachments using php and smtp. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

54  +    =  58

We accept paid advance and paid guest Posting on our Site : Contact US