PHP Classes

Errors delivering message

Recommend this page to a friend!

      SMTP E-mail sending class  >  All threads  >  Errors delivering message  >  (Un) Subscribe thread alerts  
Subject:Errors delivering message
Summary:Having trouble sending messages via smtp server or directly
Messages:12
Author:Paul Gutches
Date:2009-11-14 02:38:52
Update:2009-11-24 22:51:44
 
  1 - 10   11 - 12  

  1. Errors delivering message   Reply   Report abuse  
Picture of Paul Gutches Paul Gutches - 2009-11-14 02:38:52
Hi,

I am currently trying the test_smtp_message.php script with supporting files email_message.php, smtp_message.php, and smtp.php.

With the current params, it seems able to easily make the connection to my smtp server, via pop3 or through a direct connection to the recipient's smtp server, but in all cases the message cannot be ultimately delivered.

When sending through my authenticating outbound mail server, with or without POP3 auth, I connect, but get an empty error:
Error: +OK CommuniGate Pro POP3 Server ready

When sending directly, I get an invalid recipient error, even though the the recipients I've tried are absolutely valid:
Invalid recipient: paul@mydomain.com Error: +OK <22938.1258165690@mydomain.com> Error: it were not specified any valid recipients
(where "mydomain" is a valid personal domain)

I have tried just about every combination of variable, from direct, to tls, to pop3, etc. Anyone have any hints on how I can go about figuring out why my messages are not getting delivered?

Thanks

Paul G




  2. Re: Errors delivering message   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-11-14 03:15:40 - In reply to message 1 from Paul Gutches
I doubt that you really need POP 3 authentication these days. That was just for old ISP systems that did not support SMTP authentication.

The message clearly says that you did not specify any valid recipients. It means that the recipients that you specified cannot be mailed by the current server for the current user.

This may happen if you did not specify an valid SMTP user and password. That should be done using the user and password variables of the class as you may see in the example script.

  3. Re: Errors delivering message   Reply   Report abuse  
Picture of Paul Gutches Paul Gutches - 2009-11-14 05:15:50 - In reply to message 2 from Manuel Lemos
Thanks Manuel.

I double checked my smtp user and password, and they are correct. when using pop3 auth, it successfully echoed back the number of messages I have on the smtp mail server, proving the combo must be right.

It's the same combo that I use for my email account in Mail.app on Mac when connecting to the same outbound mail server, using the same port (110)

But I just tried port 25 and got some more messaging (shown at the bottom of this post
), but still no sent message!


Here is what I am working with... (some data changed for security reasons)

........................................


<code>
<?php
/*
* test_smtp_message.php
*
* @(#) $Header: /home/mlemos/cvsroot/mimemessage/test_smtp_message.php,v 1.14 2009/04/12 08:20:39 mlemos Exp $
*
*/


//exit;


require("email_message.php");
require("smtp_message.php");
require("smtp.php");
/* Uncomment when using SASL authentication mechanisms */

//require("sasl.php");


$from_name=getenv("USERNAME");
$from_address="paul@smtpdomain.com"; $sender_line=__LINE__;
$reply_name=$from_name;
$reply_address=$from_address;
//$reply_address=$from_address;
$error_delivery_name=$from_name;
$error_delivery_address=$from_address;
$to_name="Paul";
$to_address="paul@recipientdomain.com"; // on yet a third computer $recipient_line=__LINE__;
$subject="Testing Manuel Lemos' Email SMTP sending PHP class";
$message="Hello ".strtok($to_name," ").",\n\nThis message is just to let you know that your SMTP e-mail sending class is working as expected.\n\nThank you,\n$from_name";

if(strlen($from_address)==0)
die("Please set the messages sender address in line ".$sender_line." of the script ".basename(__FILE__)."\n");
if(strlen($to_address)==0)
die("Please set the messages recipient address in line ".$recipient_line." of the script ".basename(__FILE__)."\n");

$email_message=new smtp_message_class;

/* This computer address */
$email_message->localhost="local.server.name";

/* SMTP server address, probably your ISP address,
* or smtp.gmail.com for Gmail
* or smtp.live.com for Hotmail */
$email_message->smtp_host="mail.smtpdomain.com";

/* SMTP server port, usually 25 but can be 465 for Gmail */
$email_message->smtp_port=25; // also tried port 110, which is what I have set for my outbound mail server in my desktop client

/* Use SSL to connect to the SMTP server. Gmail requires SSL */
$email_message->smtp_ssl=0;

/* Use TLS after connecting to the SMTP server. Hotmail requires TLS */
$email_message->smtp_start_tls=1;

/* Deliver directly to the recipients destination SMTP server */
$email_message->smtp_direct_delivery=0;

/* In directly deliver mode, the DNS may return the IP of a sub-domain of
* the default domain for domains that do not exist. If that is your
* case, set this variable with that sub-domain address. */
$email_message->smtp_exclude_address="";

/* If you use the direct delivery mode and the GetMXRR is not functional,
* you need to use a replacement function. */
/*
$_NAMESERVERS=array();
include("rrcompat.php"); // file is present at script root
$email_message->smtp_getmxrr="_getmxrr";
*/

/* authentication user name */
$email_message->smtp_user="paul@smtpdomain.com";

/* authentication password */
$email_message->smtp_password="my_correct_pw_for_above_email_account";

/* if you need POP3 authetntication before SMTP delivery,
* specify the host name here. The smtp_user and smtp_password above
* should set to the POP3 user and password*/
$email_message->smtp_pop3_auth_host="";

/* authentication realm or Windows domain when using NTLM authentication */
$email_message->smtp_realm="";

/* authentication workstation name when using NTLM authentication */
$email_message->smtp_workstation="";

/* force the use of a specific authentication mechanism */
$email_message->smtp_authentication_mechanism="";

/* Output dialog with SMTP server */
$email_message->smtp_debug=1;

/* if smtp_debug is 1,
* set this to 1 to make the debug output appear in HTML */
$email_message->smtp_html_debug=1;

/* If you use the SetBulkMail function to send messages to many users,
* change this value if your SMTP server does not accept sending
* so many messages within the same SMTP connection */
$email_message->maximum_bulk_deliveries=100;

$email_message->SetEncodedEmailHeader("To",$to_address,$to_name);
$email_message->SetEncodedEmailHeader("From",$from_address,$from_name);
$email_message->SetEncodedEmailHeader("Reply-To",$reply_address,$reply_name);
$email_message->SetHeader("Return-Path",$error_delivery_address);
$email_message->SetEncodedEmailHeader("Errors-To",$error_delivery_address,$error_delivery_name);
$email_message->SetEncodedHeader("Subject",$subject);
$email_message->AddQuotedPrintableTextPart($email_message->WrapText($message));
$error=$email_message->Send();
for($recipient=0,Reset($email_message->invalid_recipients);$recipient<count($email_message->invalid_recipients);Next($email_message->invalid_recipients),$recipient++)
echo "Invalid recipient: ",Key($email_message->invalid_recipients)," Error: ",$email_message->invalid_recipients[Key($email_message->invalid_recipients)],"\n";
if(strcmp($error,""))
echo "Error: $error\n";
else
echo "Done.\n";
?>
</code>



here is the output:

Resolving SMTP server domain "mail.smtpdomain.com"...
Connecting to host address "67.99.202.39" port 25...
Connected to SMTP server "mail.smtpdomain.com".
S 220 mailserver.net ESMTP CommuniGate Pro is glad to see you!
C EHLO local.server.name
S 250-mailserver.net is pleased to meet you
S 250-DSN
S 250-SIZE 26214400
S 250-STARTTLS
S 250-ETRN
S 250-TURN
S 250-ATRN
S 250-NO-SOLICITING
S 250-HELP
S 250-PIPELINING
S 250 EHLO
C STARTTLS
S 220 please start a TLS connection
Starting TLS cryptograpic protocol
TLS started
C EHLO local_server_name
S 250-mailserver.net is pleased to meet you
S 250-DSN
S 250-SIZE 26214400
S 250-ETRN
S 250-TURN
S 250-ATRN
S 250-NO-SOLICITING
S 250-HELP
S 250-PIPELINING
S 250 EHLO
Error: server does not require authentication

// note... when TLS is set to zero, it suggests it be set to 1







  4. Re: Errors delivering message   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-11-14 05:29:41 - In reply to message 3 from Paul Gutches
Just because POP3 authenticate successfully and it returns how many messages you have in your mailbox, it does not mean that you need to do POP3 authentication to be able to send messages. It does not hurt doing it, it just may be a needless step.

Anyway, if starting TLS returns a response saying your SMTP server does not need to authenticate, that means that you do not need to specify an user and password to authenticate. So try setting the user and password variable to an empty value and remove the POP3 authentication option.

BTW, although this may not be your problem, the recommendation is that you use the SMTP class in conjunction with the MIME message class, as it is the way to go to compose e-mail standards compliant messages.

phpclasses.org/mimemessage

  5. Re: Errors delivering message   Reply   Report abuse  
Picture of Paul Gutches Paul Gutches - 2009-11-14 06:30:13 - In reply to message 4 from Manuel Lemos

Thanks again.

I just tried it without a user name and password, and it worked!

I would never have guesses that was the problem. Thank you.

I'm having trouble understanding why my desktop email client requires a u/p and port 110 to send outbound email, and your script requires no u/p and works on port 25?

Is it because I am sending the message from a server that is operated by the same company?

Appreciate your help.

Great script. I tried 4 others before yours and gave up on all of them.

Regards,

Paul




  6. Re: Errors delivering message   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-11-14 06:54:50 - In reply to message 5 from Paul Gutches
Maybe. Keep in mind that your desktop client also pulls e-mail from a POP 3 server, so that may be the only reason why it needs to access the POP 3 server.

  7. Header encoding problem?   Reply   Report abuse  
Picture of Paul Gutches Paul Gutches - 2009-11-24 20:06:22 - In reply to message 5 from Paul Gutches
Well... I'm _almost_ home!

Turns out, having gotten back to this project, that while the mail is in fact sent via SMTP (80% of the battle), the headers appear to be misinterpreted or somehow malformed.

The context of my problem, is that I am trying to automatically send list commands to a list serve.

The list serve (DLIST), is looking for the command in the body of the message, but instead it finds a "From: " header and so aborts the process. Could it be that something is not being encoded properly?

Here is the script output (edited for privacy), followed by the DLIST message. Hope you can tell what's wrong here.

Resolving SMTP server domain "mail.domain.tld"...
Connecting to host address "xx.xx.xxx.xx" port 25...
Connected to SMTP server "mail.domain.tld".
S 220 server.net ESMTP CommuniGate Pro is glad to see you!
C EHLO server.net
S 250-server.net your name is not server.net
S 250-DSN
S 250-SIZE 26214400
S 250-STARTTLS
S 250-ETRN
S 250-TURN
S 250-ATRN
S 250-NO-SOLICITING
S 250-HELP
S 250-PIPELINING
S 250 EHLO
C STARTTLS
S 220 please start a TLS connection
Starting TLS cryptograpic protocol
TLS started
C EHLO server.net
S 250-server.net your name is not server.net
S 250-DSN
S 250-SIZE 26214400
S 250-ETRN
S 250-TURN
S 250-ATRN
S 250-NO-SOLICITING
S 250-HELP
S 250-PIPELINING
S 250 EHLO
C MAIL FROM:<user@domain.tld>
C RCPT TO:<recipient@domain2.com>
C DATA
S 250 user@domain.tld sender accepted
S 250 recipient@domain2.com accepting mail from a client address
S 354 Enter mail, end with "." on a line by itself
C To: Recipient <recipient@domain2.com>

From: =?ISO-8859-1?q?sender=40domain.tld?= <sender@domain.tld>
Reply-To: =?ISO-8859-1?q?sender=40domain.tld?= <sender@domain.tld>
Return-Path: sender@domain.tld
Errors-To: =?ISO-8859-1?q?sender=domain.tld?= <sender@domain.tld>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Date: Tue, 24 Nov 2009 12:32:03 MST
Message-ID: <20091124123203.1796.sender@domain.tld>


C who

=2E

C
.
S 250 441453749 message accepted for delivery
C QUIT
S 221 server.net CommuniGate Pro SMTP closing connection
Disconnected.
Done.




----------------- and here is what I receive from the request at the address
as you can see, there is some odd encoding around the sender address and the "From: " header has slipped into the body content. Thoughts?


--DLIST-Command--> From: =?ISO-8859-1?q?sender=40domain.tld?=
Unknown list command (from:), stopping processing
Valid commands:
join Join the list
digest true/false Request digest version
leave [address] Leave the list
lists Returns all lists on this host
dir Returns list of files available for retrieval
get filename Returns a file
get n-m Returns old messages to the list
help Send detailed help
who Return list of users on this list
end Stop processing commands (or blank line)
Some commands are only available to members or moderators of the list
Note: you may have to turn off 'html/mime' formatting before posting a command.


  8. SPAM flagging ....   Reply   Report abuse  
Picture of Paul Gutches Paul Gutches - 2009-11-24 20:09:55 - In reply to message 7 from Paul Gutches

one other item...

the responses are failing the SPAM test. I think this will resolve itself once the header issue is resolved. But, just to be thorough, the server is complaining about:

0.01 INVALID_DATE Invalid Date: header (not RFC 2822)
1.58 MISSING_HEADERS Missing To: header
1.76 INVALID_DATE_2 Invalid Date: header (not RFC 2822)



Paul

  9. Re: Errors delivering message   Reply   Report abuse  
Picture of Paul Gutches Paul Gutches - 2009-11-24 20:28:38 - In reply to message 7 from Paul Gutches


and... yet another note...

the mail headers suggest that
"Note: you may have to turn off 'html/mime' formatting before posting a command."

Is that relevant to this script?


  10. Re: Errors delivering message   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-11-24 20:57:42 - In reply to message 7 from Paul Gutches
It seems the body message is malformed.

You need to use the MIME message class to compose and send messages in conjunction with the SMTP class for composing and sending correctly formed messages:

phpclasses.org/mimemessage

 
  1 - 10   11 - 12