Send PHP E-mail From Gmail SMPT

Send PHP E-mail From Gmail SMPT


SEND PHP E-MAIL FROM GMAIL SMPT

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.
1<?php
2 
3 require_once('class.phpmailer.php');
4  
5 $mail new PHPMailer();
6 $mail->CharSet = "utf-8";
7 $mail->IsSMTP();
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";
13 $mail->Port = "465";
14  
15 $mail->setFrom('your_gmail@gmail.com''your name');
16 $mail->AddAddress('to_mail@mail.com''receivers name');
17  
18 $mail->Subject = 'using PHPMailer';
19 $mail->IsHTML(true);
20 $mail->Body = 'Hi there ,
21 <br />
22 this mail was sent using PHPMailer...
23 <br />
24 cheers... :)';
25  
26 if($mail->Send())
27 {
28 echo "Message was Successfully Send :)";
29 }
30 else
31 {
32 echo "Mail Error - >".$mail->ErrorInfo;
33 }
34  
35?>

CODE 2

use this script if you download the PHP Mailer From GitHub page
1<?php
2require 'PHPMailerAutoload.php';
3  
4$mail new PHPMailer;
5  
6$mail->isSMTP(); // Set mailer to use SMTP
7$mail->Host = 'smtp.gmail.com'// Specify main and backup server
8$mail->SMTPAuth = true; // Enable SMTP authentication
9$mail->Username = 'veer@gmail.com'// SMTP username
10$mail->Password = 'password'// SMTP password
11$mail->SMTPSecure = 'tls'// Enable encryption, 'ssl' also accepted
12$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
13$mail->setFrom('veer@gmail.com''veer'); //Set who the message is to be sent from
14$mail->addReplyTo('mskv@gmail.com''First Last'); //Set an alternative reply-to address
15$mail->addAddress('josh@example.net''Josh Adams'); // Add a recipient
16$mail->addAddress('ellen@example.com'); // Name is optional
17$mail->addCC('cc@example.com');
18$mail->addBCC('bcc@example.com');
19$mail->WordWrap = 50; // Set word wrap to 50 characters
20$mail->addAttachment('/usr/mskv/file.doc'); // Add attachments
21$mail->addAttachment('/images/image.jpg''new.jpg'); // Optional name
22$mail->isHTML(true); // Set email format to HTML
23  
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';
27  
28//Read an HTML message body from an external file, convert referenced images to embedded,
29//convert HTML into a basic plain-text alternative body
30$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
31  
32if(!$mail->send()) {
33 echo 'Message could not be sent.';
34 echo 'Mailer Error: ' $mail->ErrorInfo;
35 exit;
36}
37  
38echo 'Message has been sent';</pre>
39?>

Now run this Two codes on your Localhost before that check if you are connecting your internet SMPT needs Net Connection.

PHP PLUGIN

Comments

Popular posts from this blog

NewsDog WeMedia - Write smarter, grow faster and earn better

7 Latest Trends In The Logo Designing World