When you are tesPHPMailerdeveloped by the PHPMailer team. It makes the job very easy and you can send SMTP mail easily from your local server. It is very easy to integrate the library to your web applications.
Download
Download PHPMailer library from https://github.com/PHPMailer/PHPMailer.
Usage Instructions
Here I am using my Gmail account to send SMTP mail. You can also configure other services such as Yahoo , Outlook to send mail using SMTP. Create a file named mail.php outside the downloaded PHPMailer directory and use the code similar to the sample given below.
PHP Code
<?phprequire 'PHPMailer/PHPMailerAutoload.php';$mail = new PHPMailer;$mail->isSMTP();$mail->Host = 'smtp.gmail.com';$mail->SMTPAuth = true;$mail->Username = 'raj.amalw@gmail.com';$mail->Password = '******';$mail->SMTPSecure = 'tls';$mail->From = 'raj.amalw@gmail.com';$mail->FromName = 'Raj Amal';$mail->addAddress('raj.amalw@learn2crack.com', 'Raj Amal W');$mail->addReplyTo('raj.amalw@gmail.com', 'Raj Amal W');$mail->WordWrap = 50;$mail->isHTML(true);$mail->Subject = 'Using PHPMailer';$mail->Body = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost';if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit;}echo 'Message has been sent'; |
The SMTP host of Gmail is smtp.gmail.com. It will vary for Outlook and Yahoo mail. The to Address should be set in addAddress(). I think it will be really helpful for you guys.

0 comments:
Post a Comment