SEND PHP E-MAIL FROM GMAIL SMPT
Hai Friends today we are coming with interesting tutorial Send PHP E-mail From Gmail SMPT recently one of my Client ask me a tutorial for Gmail SMPT For PHP Contact Form in this tutorial we are going to see about Send PHP E-mail From Gmail SMPT.Mostly Gmail SMPT Was help us to send and receive mail From our localhost we can use Gmail SMPT for contact form, registration and more PHP related web forms ok let’s come to the tutorial.
WHERE WE USE THE GMAIL SMPT SERVICE IN PHP?
- Contact Form
- Registration form
- Mail Form
- Feedback form
- And More Mail Function Related Form’s
PHP CODE FOR PHPMAILER
I have two types of PHP Code for Gmail SMPT
CODE 1
Use this PHP code if you download the PHP mailer From Sourceforge Page.
3 | require_once ( 'class.phpmailer.php' ); |
5 | $mail = new PHPMailer(); |
6 | $mail ->CharSet = "utf-8" ; |
8 | $mail ->SMTPAuth = true; |
9 | $mail ->Username = "your_gmail@gmail.com" ; |
10 | $mail ->Password = "your_gmail_password" ; |
11 | $mail ->SMTPSecure = "ssl" ; |
12 | $mail ->Host = "smtp.gmail.com" ; |
15 | $mail ->setFrom( 'your_gmail@gmail.com' , 'your name' ); |
16 | $mail ->AddAddress( 'to_mail@mail.com' , 'receivers name' ); |
18 | $mail ->Subject = 'using PHPMailer' ; |
20 | $mail ->Body = 'Hi there , |
22 | this mail was sent using PHPMailer... |
28 | echo "Message was Successfully Send :)" ; |
32 | echo "Mail Error - >" . $mail ->ErrorInfo; |
CODE 2
use this script if you download the PHP Mailer From GitHub page
2 | require 'PHPMailerAutoload.php' ; |
7 | $mail ->Host = 'smtp.gmail.com' ; |
9 | $mail ->Username = 'veer@gmail.com' ; |
10 | $mail ->Password = 'password' ; |
11 | $mail ->SMTPSecure = 'tls' ; |
13 | $mail ->setFrom( 'veer@gmail.com' , 'veer' ); |
14 | $mail ->addReplyTo( 'mskv@gmail.com' , 'First Last' ); |
15 | $mail ->addAddress( 'josh@example.net' , 'Josh Adams' ); |
16 | $mail ->addAddress( 'ellen@example.com' ); |
17 | $mail ->addCC( 'cc@example.com' ); |
18 | $mail ->addBCC( 'bcc@example.com' ); |
20 | $mail ->addAttachment( '/usr/mskv/file.doc' ); |
21 | $mail ->addAttachment( '/images/image.jpg' , 'new.jpg' ); |
24 | $mail ->Subject = 'Here is the subject' ; |
25 | $mail ->Body = 'This is the HTML message body <b>in bold!</b>' ; |
26 | $mail ->AltBody = 'This is the body in plain text for non-HTML mail clients' ; |
30 | $mail ->msgHTML( file_get_contents ( 'contents.html' ), dirname( __FILE__ )); |
33 | echo 'Message could not be sent.' ; |
34 | echo 'Mailer Error: ' . $mail ->ErrorInfo; |
38 | echo 'Message has been sent' ;</pre> |
Now run this Two codes on your Localhost before that check if you are connecting your internet SMPT needs Net Connection.
PHP PLUGIN
Comments
Post a Comment