-
Notifications
You must be signed in to change notification settings - Fork 2
/
cGmailSMTP.php
72 lines (59 loc) · 2.77 KB
/
cGmailSMTP.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/* $Id: cGmailSMTP.php,v 0.1 2010/10/16 20:11:45 aedavies Exp $ */
interface iGmailSMTP {
public static function gmail( $from, $namefrom, $to, $nameto, $subject, $message );
}
class cGmailSMTP implements iGmailSMTP {
public static function gmail( $from, $namefrom, $to, $nameto, $subject, $message ) {
$newLine = "\r\n";
$smtpConnect;
$smtpResponse;
$logArray=array();
$this->smtpConnect = fsockopen( "tcp:https://alt4.gmail-smtp-in.l.google.com", 25, $errno, $errstr, 15 );
$this->smtpResponse = fgets( $this->smtpConnect, 515 );
if( $this->smtpConnect ) {
$this->logArray['connect'] = $this->smtpResponse;
}
fputs( $this->smtpConnect, "HELO localhost" . $this->newLine );
$this->smtpResponse = fgets( $this->smtpConnect, 515 );
$this->logArray['helo'] = $this->smtpResponse;
fputs( $this->smtpConnect, "MAIL FROM: <$from>" . $this->newLine );
$this->smtpResponse = fgets( $this->smtpConnect, 515 );
$this->logArray['from'] = $this->smtpResponse;
fputs( $this->smtpConnect, "RCPT TO: <$to>" . $this->newLine );
$this->smtpResponse = fgets( $this->smtpConnect, 515 );
$this->logArray['to'] = $this->smtpResponse;
fputs( $this->smtpConnect, "DATA". $this->newLine );
$this->smtpResponse = fgets( $this->smtpConnect, 515 );
$this->logArray['data'] = $this->smtpResponse;
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
$fmsg = "To: $to\r\n";
$fmsg .= "From: $from\r\n";
$fmsg .= "Subject: $subject\r\n";
$fmsg .= "$headers\r\n\r\n";
$fmsg .= "$message\r\n";
$fmsg .= ".\r\n";
fputs( $this->smtpConnect, $fmsg );
$smtpResponse = fgets( $this->smtpConnect, 515 );
$this->logArray['message'] = $this->smtpResponse;
fputs( $this->smtpConnect, "QUIT".$this->newLine );
$this->smtpResponse = fgets( $this->smtpConnect, 515 );
$this->logArray['quit'] = $this->smtpResponse;
#echo nl2br(var_export($logArray));
}
}
/* Usage:
$to = "[email protected]";
$nameto = "laudarch";
$from = "[email protected]";
$namefrom = "laudarch";
$subject = "smtp testing 1.2.3.";
$message = "does this work ... yes it does ... yadda yadda yadda";
#smtp($from, $namefrom, $to, $nameto, $subject, $message);
global $logArray;
print_r($logArray);
*/
?>