Code style changed, ext-user continued:
[mailer.git] / inc / phpmailer / examples / test_gmail.php
1 <?php
2
3 include("class.phpmailer.php");
4 //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
5
6 $mail             = new PHPMailer();
7
8 $body             = $mail->getFile('contents.html');
9 $body             = eregi_replace("[\]",'',$body);
10
11 $mail->IsSMTP();
12 $mail->SMTPAuth   = TRUE;                  // enable SMTP authentication
13 $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
14 $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
15 $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
16
17 $mail->Username   = "yourusername@gmail.com";  // GMAIL username
18 $mail->Password   = "yourpassword";            // GMAIL password
19
20 $mail->AddReplyTo("yourusername@gmail.com","First Last");
21
22 $mail->From       = "name@yourdomain.com";
23 $mail->FromName   = "First Last";
24
25 $mail->Subject    = "PHPMailer Test Subject via gmail";
26
27 //$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
28 $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
29 $mail->WordWrap   = 50; // set word wrap
30
31 $mail->MsgHTML($body);
32
33 $mail->AddAddress("whoto@otherdomain.com", "John Doe");
34
35 $mail->AddAttachment("images/phpmailer.gif");             // attachment
36
37 $mail->IsHTML(TRUE); // send as HTML
38
39 if(!$mail->Send()) {
40   echo "Mailer Error: " . $mail->ErrorInfo;
41 } else {
42   echo "Message sent!";
43 }
44
45 ?>