lmaster Posted November 25, 2008 Share Posted November 25, 2008 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??? Quote Link to comment https://forums.phpfreaks.com/topic/134245-help-pear-smtp-mail-on-windows-xp-open-to-othe-options/ Share on other sites More sharing options...
bluesoul Posted November 25, 2008 Share Posted November 25, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/134245-help-pear-smtp-mail-on-windows-xp-open-to-othe-options/#findComment-698889 Share on other sites More sharing options...
DeanWhitehouse Posted November 25, 2008 Share Posted November 25, 2008 http://phpmailer.codeworxtech.com/ http://uk.php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/134245-help-pear-smtp-mail-on-windows-xp-open-to-othe-options/#findComment-698898 Share on other sites More sharing options...
lmaster Posted November 25, 2008 Author Share Posted November 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/134245-help-pear-smtp-mail-on-windows-xp-open-to-othe-options/#findComment-698959 Share on other sites More sharing options...
bluesoul Posted November 26, 2008 Share Posted November 26, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/134245-help-pear-smtp-mail-on-windows-xp-open-to-othe-options/#findComment-699155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.