Jump to content

HELP!! - PEAR SMTP Mail, on Windows XP - OPEN TO OTHE OPTIONS...


lmaster

Recommended Posts

Sending Email with PHP

 

All, I'm following this article to a tea, but getting the following error message:

 

http://www.developer.com/open/article.php/10930_3782831_1

 

 

after I install the packages and run my script! 

 

C:\php>php mailer1.php

PHP Fatal error:  Call to undefined method PEAR_Error::send() in C:\php\mailer1.

php on line 24

 

If ANYBODY knows of a better tutorial on how to use this, please respond, unfortunately, this article is very high on the Google results page and many folks are referring to it...

 

All I am trying to do is use Google's SMTP server, port 465 with SSL etc, I understand that the stock mail() function within PHP does not work with encryption/authentication.  Any body has a better idea???

Link to comment
Share on other sites

It is possible to connect via telnet and send mail that way, it's not nearly as elegant as using a PEAR module but I didn't have PEAR available to me when I made the following.

 

<html><body>
<pre>
<?
function authSendEmail() {
global $to;
global $from;
global $subject;
global $message;
$localhost = "localhost";
$username = "smtp_username"; // set to your smtp username
$password = "smtp_password"; // and password
$smtpConnect = fsockopen('192.168.161.142', 25); // change to your SMTP server, leave the port
socket_set_blocking($smtpConnect,1);
$smtpResponse = fgets($smtpConnect, 515);
$newLine = chr(10);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
echo('Opening Connection to Mail server...<br>>>'.$smtpResponse.'<br>');
}
$str = "AUTH LOGIN" . $newLine;
//Request Auth Login
$test = fputs($smtpConnect,$str,strlen($str));
$smtpResponse = fgets($smtpConnect);
echo('AUTH LOGIN<br>>>'.$smtpResponse.'<br>');

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
echo (base64_encode($username).'<br>>>'.$smtpResponse.'<br>');

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
echo (base64_encode($password).'<br>>>'.$smtpResponse.'<br>');

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
echo ('HELO localhost<br>>>'.$smtpResponse.'<br>');

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
echo ('MAIL FROM: '.$from.'<br>>>'.$smtpResponse.'<br>');

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
echo ('RCPT TO: '.$to.'<br>>>'.$smtpResponse.'<br>');

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
echo ('DATA<br>>>'.$smtpResponse.'<br>');

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $newLine;
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 515);
echo ('To: '.$to.'<br>From: '.$from.'<br>Subject: '.$subject.'<br>'.$headers.'<br><br>'.$message.'<br>.<br><br>>>'.$smtpResponse.'<br>');

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
echo ('QUIT<br>>>'.$smtpResponse.'<br>');
}


/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,



$to = "destination@example.com";
$from = "sender@example.com";
$subject = "Test";
$message = "Message goes here.";
authSendEmail($from, $to, $subject, $message);

?>
</pre></body></html>

 

I wrote that so I could see my errors as they encountered and make fixes accordingly.  If you're using ESMTP it should work perfectly (tested on an IMail platform), feel free to adapt it to your needs (removing the echoes etc).

Link to comment
Share on other sites

BlueSoul and Blade280891, unfortunately the code you referenced does not help me becasue Google uses SMTP-AUTH and TLS.  With the Telnet Script that BlueSoul posted here is the response from Google's SMTP server

 

C:\php>php mailer2.php

Opening Connection to Mail server...<br>>>220 mx.google.com ESMTP 6sm13367791yxg

.6

<br>AUTH LOGIN<br>>>503 5.5.1 EHLO/HELO first. 6sm13367791yxg.6

<br>dGF4YW5kYWNjb3VudGluZ2Fzc29jQGdtYWlsLmNvbQ==<br>>>502 5.5.1 Unrecognized com

mand. 6sm13367791yxg.6

<br>dGF4YTY3ODk=<br>>>502 5.5.1 Unrecognized command. 6sm13367791yxg.6

<br>HELO localhost<br>>>250 mx.google.com at your service

<br>MAIL FROM: taxandaccountingassoc@gmail.com<br>>>530 5.7.0 Must issue a START

TLS command first. 6sm13367791yxg.6

<br>RCPT TO: taxandaccountingassoc@gmail.com<br>>>530 5.7.0 Must issue a STARTTL

S command first. 6sm13367791yxg.6

Link to comment
Share on other sites

Eh, the best thing I can tell if you if you prefer to go with that script is to check online references for TLS and tweak it until it does as it should, that was why I had the echo of both sent and received messages.  The methodology to add/change entries is pretty straightforward.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.