New and Improved - well for gmail users at least. Their SMTP
responds differently than other MTA"s. Make sure to
enable the pop mail in the gmail account settings first
function authgMail($from, $namefrom, $to, $nameto, $subject,
$message)
{
/* your configuration here */
$smtpServer = "tls://smtp.gmail.com"; //does not
accept STARTTLS
$port = "465"; // try 587 if this fails
$timeout = "45"; //typical timeout. try 45 for
slow servers
$username = "yous gmail.com"; //your gmail account
$password = "y0u4p 55"; //the pass for your gmail
$localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip
$newLine = "rn"; //var just for newlines
/* you shouldn't need to mod anything else */
//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno,
$errstr, $timeout);
echo $errstr." - ".$errno;
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
echo $output;
return $output;
}
else
{
$logArray['connection'] = "Connected to:
$smtpResponse";
echo "connection
accepted<br>".$smtpResponse."<p
/>Continuing<p />";
}
//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost".
$newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";
//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";
//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";
//email from
fputs($smtpConnect, "MAIL FROM: <$from>" .
$newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";
//email to
fputs($smtpConnect, "RCPT TO: <$to>" .
$newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";
//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";
//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html;
charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" .
$newLine;
//observe the . after the newline, it signals the end of
message
fputs($smtpConnect, "To: $tornFrom: $fromrnSubject:
$subjectrn$headersrnrn$messagern.rn");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";
// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is
a success
return($logArray);
}
----
Server IP: 208.69.120.35
Probable Submitter: 71.41.108.79
----
Manual Page -- http://www.
php.net/manual/en/ref.mail.php
Edit -- https://master
.php.net/note/edit/76014
Del: integrated -- h
ttps://master.php.net/note/delete/76014/integrated
Del: useless -- http
s://master.php.net/note/delete/76014/useless
Del: bad code -- htt
ps://master.php.net/note/delete/76014/bad+code
Del: spam -- https:/
/master.php.net/note/delete/76014/spam
Del: non-english --
https://master.php.net/note/delete/76014/non-english
Del: in docs -- http
s://master.php.net/note/delete/76014/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/76014
Reject -- https://mast
er.php.net/note/reject/76014
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|