I have this mail routine that uses SMTP. I need to get this working with gmail. Besides changing the host and the port for line $MailTo = new Smtp(“ssl://smtp.gmail.com”, “465”);, is there anything else I need to do? I can’t seem to get this working and I have no clue what to do next.
[php]
function jintek_sendmail($to, $cc, $from, $subject, $mailbody)
{
require_once("…/LIBS/mail_smtp.php");
if($from==’’)
$from="[email protected]";
$MailTo = new Smtp(“ssl://smtp.gmail.com”, “465”);
$MailTo->Subject = $subject;
$MailTo->ToEmail = $to;
$MailTo->ToName = $to;
$MailTo->FromEmail = $from;
$MailTo->Body = $mailbody;
$MailTo->contentType = “text/plain”;
$MailTo->Attachment = ‘null’;
$current_date = getdate(time());
$convertdate = “$current_date[mon]/$current_date[mday]/$current_date[year]”;
$converttime = “$current_date[hours]:$current_date[minutes]:$current_date[seconds]”;
$zone_arr=array();
$zone_arr=getUserZone();
$MailTo->sendDate = Get_Usertime($convertdate,$converttime,$zone_arr[offset],$zone_arr[zone_id]);
$error = $MailTo->Helo();
$result = 1;
if(!$error){
//print("<span class=plainattentionerror>Error: Failed to send helo command.</span><br>\n");
$result = 0;
}else{
$error = $MailTo->MailFrom();
if(!$error){
//print("<span class=plainattentionerror>Error: Failed to send mail from command.</span><br>\n");
$result = 0;
}else{
$error = $MailTo->RcptTo();
if(!$error){
//print("<span class=plainattentionerror>Error: Failed to send recieptien command.</span><br>\n");
$result = 0;
}else{
$save_outgoing = "off";
$savefilename = "tmp/pls_deleteme";
$error = $MailTo->Body($save_outgoing,$savefilename);
if(!$error){
//print("<span class=plainattentionerror>Error: Failed to send mail.</span><br>\n");
$result = 0;
}
}
}
}
$MailTo->Quit();
$MailTo = null;
return $result;
}
\n"); in RcptTo() // 08/24/2000 3:55 PM. San fixed email invitation is sent to a user in BIG SOL the email date shows up as 1970. class Smtp { var $Subject; // string the email's subject var $ToEmail; var $ToName; // string recipient's name (opt) var $CcName; var $BccName; var $FromName; // string sender's name (opt) var $FromEmail; var $Body; // string body copy var $Attachment; // attachment (optional) var $AttachmentType; var $AttachfileFolder; var $Socket; var $Line; var $Status; var $sendDate; var $attEncode; var $attCharset; var $attdisposition; var $contentType; function Smtp($Server,$Port) { return $this->Open($Server, $Port); } /* function SmtpMail($FromEmai, $ToEmai, $Subject, $Body, $Attachment=null, $AttachmentType= "TEXT") { $this->Subject = $Subject; $this->ToName = $ToEmai; $this->FromName = $FromEmai; $this->Body = $Body; $this->Attachment = $Attachment; $this->AttachmentType = $AttachmentType; if ($this->Helo() == false){ return false; } if ($this->MailFrom($FromEmai) == false){ return false; } if ($this->RcptTo($ToEmail) == false){ return false; } if ($this->Body() == false){ return false; } if ($this->Quit() == false){ return false; } } */ function Open($Server, $Port) { $this->Socket = fsockopen($Server, $Port, &$err_number, &$err_desc); /* if(!$this->Socket){ print("An error occurred!
\n"); print("Number : $err_number
\n"); print("Description: $err_desc
\n"); return false; } elseif ($this->Socket < 0) return false; */ if ($this->Socket < 0) return false; $this->Line = fgets($this->Socket, 1024); $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1); $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024); if ($this->Status[ "LASTRESULT"] <> "2") return false; return true; } function Helo() { if (fputs($this->Socket, "helo mail.coffmanspecialties.com\r\n") < 0 ){ return false; } $this->Line = fgets($this->Socket, 1024); $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1); $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024); if ($this->Status[ "LASTRESULT"] <> "2") return false; return true; } function Ehlo() { /* Well, let's use "helo" for now.. Until we need the extra func's [Unk] */ if(fputs($this->Socket, "helo mail.coffmanspecialties.com\r\n")<0){ return false; } $this->Line = fgets($this->Socket, 1024); $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1); $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024); if ($this->Status[ "LASTRESULT"] <> "2") return false; return true; } function MailFrom() { // if (fputs($this->Socket, "MAIL FROM: <$this->FromEmail>\r\n")<0){ if (fputs($this->Socket, "MAIL FROM: \"admin\" \r\n")<0){ return false; } $this->Line = fgets($this->Socket, 1024); $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1); $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024); if ($this->Status[ "LASTRESULT"] <> "2") return false; return true; } function RcptTo() { $rcpt_arr = explode(",",$this->ToEmail); $total = count($rcpt_arr); $cnt_err = 0; for($i=0;$i<$total;$i++){ $to_rcpt = $rcpt_arr[$i]; if(fputs($this->Socket, "RCPT TO: <$to_rcpt>\r\n")<0){ return false; } $this->Line = fgets($this->Socket, 1024); $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1); $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024); if ($this->Status[ "LASTRESULT"] <> "2"){ $error = substr($this->Status[ "LASTRESULTTXT"],4,1024); //print("ERROR($to_rcpt): $error
\n"); $cnt_err++; } } if($cnt_err==$total) return false; return true; } function Body($save,$savename) { require_once("../LIBS/mailfunctions.php"); $FileSize = 0; $Attachment = null; $fp = null; if($save) $fhandle = fopen($savename,"w"); $buffer = ''; //$buffer = sprintf( "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n", $this->FromName, $this->ToName, $this->Subject, $this->sendDate); // $buffer = "Date: Wed, 6 Jun 2001 13:32:38 -0700\r\n"; //## fixed time stamp incorrect $current_date = getdate(time()); $convertdate = "$current_date[mon]/$current_date[mday]/$current_date[year]"; $converttime = "$current_date[hours]:$current_date[minutes]:$current_date[seconds]"; $usr_cv_tmstm = strtotime("$convertdate $converttime"); $new_date = date('D, d M Y H:i:s',$usr_cv_tmstm); $this->sendDate = "$new_date -0700"; $buffer .= "From: ".$this->FromEmail."\r\n"; $buffer .= "To: ".strtok($this->ToName,","); for($token=strtok(","),$tmp_ind=1;$token!="";$token=strtok(",")){ $tmp_ind++; if(($tmp_ind%2)==0) $buffer .= ", $token"; else $buffer .= ",\r\n\t$token"; } $buffer .= "\r\n"; if($this->CcName!=""){ $buffer .= "Cc: ".strtok($this->CcName,","); for($token=strtok(","),$tmp_ind=1;$token!="";$token=strtok(",")){ $tmp_ind++; if(($tmp_ind%2)==0) $buffer .= ", $token"; else $buffer .= ",\r\n\t$token"; } $buffer .= "\r\n"; } $buffer2 = $buffer ; if($this->BccName!=""){ $buffer2 .= "Bcc: ".strtok($this->BccName,","); for($token=strtok(","),$tmp_ind=1;$token!="";$token=strtok(",")){ $tmp_ind++; if(($tmp_ind%2)==0) $buffer2 .= ", $token"; else $buffer2 .= ",\r\n\t$token"; } $buffer2 .= "\r\n"; } $buffer .= "Subject: ".$this->Subject."\r\n"; $buffer2 .= "Subject: ".$this->Subject."\r\n"; $buffer .= "Date: ".$this->sendDate."\r\n"; $buffer2 .= "Date: ".$this->sendDate."\r\n"; if(fputs($this->Socket, "DATA\r\n")<0){ return false; } $this->Line = fgets($this->Socket, 1024); $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1); $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024); if ($this->Status[ "LASTRESULT"] <> "3") return false; if(fputs($this->Socket, $buffer)<0){ return false; } if($save){ $buffer2 = ereg_replace("\r","",$buffer2); // fputs($fhandle,"!!!from ScheduleOnline_webbaseemail\t\t\t\tSaved-Sent\n$buffer2"); fputs($fhandle,$buffer2); } if(empty($this->contentType)) $this->contentType = "text/plain"; if ($this->Attachment == 'null'){ //$mime_header = "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Transfer-Encoding: 7bit\r\n\r\n"; $mime_header = "MIME-Version: 1.0\r\nContent-Type: ".$this->contentType."; charset=us-ascii\r\n\r\n"; if(fputs($this->Socket,$mime_header)<0){ return false; } if($save){ $mime_header = ereg_replace("\r","",$mime_header); fputs($fhandle,$mime_header); } if(fputs($this->Socket, "$this->Body\r\n\r\n")<0){ return false; } if($save) fputs($fhandle,"$this->Body\n\n"); if(fputs($this->Socket, ".\r\n")<0){ return false; } $this->Line = fgets($this->Socket, 1024); if (substr($this->Line, 0, 1) <> "2"){ return false; }else{ return true; } }else{ /*$mime_header = "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"----=_NextPart_000_01BCFA61.A3697360\"\r\n". "Content-Transfer-Encoding: 7bit\r\n\r\n". "This is a multi-part message in MIME format.\r\n". "\r\n------=_NextPart_000_01BCFA61.A3697360\r\n". "Content-Type: text/plain; charset=ISO-8859-1\r\n". "Content-Transfer-Encoding: 7bit\r\n". "\r\n";*/ if ($this->attCharset == null) $this->attCharset = "us-ascii"; $mime_header = "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"----=_NextPart_000_01BCFA61.A3697360\"\r\n". "Content-Transfer-Encoding: 7bit\r\n\r\n". "This is a multi-part message in MIME format.\r\n". "\r\n------=_NextPart_000_01BCFA61.A3697360\r\n". "Content-Type: ".$this->contentType."; charset=".$this->attCharset."\r\n". "\r\n"; if(fputs($this->Socket,$mime_header)<0){ return false; } if($save){ $mime_header = ereg_replace("\r","",$mime_header); fputs($fhandle,$mime_header); } /* output the body file */ if(fputs($this->Socket, "$this->Body\r\n\r\n")<0){ return false; } if($save) fputs($fhandle,"$this->Body\n\n"); $attachfile_arr = explode(",",$this->Attachment); $attachtype_arr = explode(",",$this->AttachmentType); for($i=0;$iattEncode != null) $encoding = "$this->attEncode"; else $encoding = "8bit"; else $encoding = "base64"; if ( fputs($this->Socket, "\r\n------=_NextPart_000_01BCFA61.A3697360\r\n")<0){ return false; } if($save) fputs($fhandle,"\n------=_NextPart_000_01BCFA61.A3697360\n"); $FileSize = filesize("$this->AttachfileFolder/$attachfile_arr[$i]"); if ($FileSize == false){ return false; } if (($fp = fopen("$this->AttachfileFolder/$attachfile_arr[$i]", "r"))== false) { return false; }else{ $Attachment = fread($fp,$FileSize); } if ($this->attdisposition == null) $this->attdisposition = "attachment"; $content_header = "Content-Type: $attachtype_arr[$i]; \r\n name=\"$attachfile_arr[$i]\"\r\n". "Content-Transfer-Encoding: $encoding\r\n". // "Content-Description: $attachfile_arr[$i]\r\n". "Content-Disposition: ".$this->attdisposition."; filename=\"$attachfile_arr[$i]\"\r\n". "\r\n"; if( fputs($this->Socket,$content_header)<0){ return false; } if($save){ $content_header = ereg_replace("\r","",$content_header); fputs($fhandle,$content_header); } /* output the attachment file */ if($encoding == "base64"){ $Attachment = base64_encode($Attachment); } if( fputs($this->Socket, $Attachment)<0){ return false; } if($save) fputs($fhandle,$Attachment); if ( fputs($this->Socket, "\r\n")<0){ return false; } if($save) fputs($fhandle,"\n"); } if ( fputs($this->Socket, "\r\n------=_NextPart_000_01BCFA61.A3697360--\r\n")<0){ return false; } if($save) fputs($fhandle,"\n------=_NextPart_000_01BCFA61.A3697360--\n"); if( fputs($this->Socket, ".\r\n")<0){ return false; } $this->Line = fgets($this->Socket, 1024); if (substr($this->Line, 0, 1) <> "2") return false; return true; } if($save) fclose($fhandle); } function Quit() { if(fputs($this->Socket, "QUIT\r\n")<0){ return false; } $this->Line = fgets($this->Socket, 1024); $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1); $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024); if ($this->Status[ "LASTRESULT"] <> "2") return 0; return 1; } function Close() { fclose($this->Socket); } } ?>
[/php]