Page 1 of 1

mail problem

Posted: Thu Dec 16, 2004 6:02 pm
by slaher
Hi

I am trying to send email using PHP's 'mail' function. I am on Windows XP Pro. The PHP code I am using is as shown below. If I connect to the mail server using Telnet (from the Command Prompt) and enter the same sequence of SMTP, it works, and I receive the test email in my yahoo account. When I execute the php script, however, no error message is displayed, yet I do not receive the test message either. Any pointers would be appreciated.

Many thanks,
-sl

------------------ sendmail.php -------------------
$smtp_server = "mail.companyname.com";
$port = 587;
$mydomain = "companyname.com";
$username = "me@companyname.com";
$password = "passwd";
$sender = "me@companyname.com";
$recipient = "my_yahoo_id@yahoo.com";
$subject = "test subj";
$content = "test contents";

// Initiate connection with the SMTP server
$handle = fsockopen($smtp_server,$port);

//$nRes = fputs($handle, "EHLO $mydomain\r\n");
// SMTP authorization
$nRes = fputs($handle, "AUTH LOGIN\r\n");

$v1 = base64_encode($username);
$v2 = base64_encode($password);

$nRes = fputs($handle, $v1."\r\n");
$nRes = fputs($handle, $v2."\r\n");

// Send out the e-mail
$nRes = fputs($handle, "HELO $mydomain\r\n");

$nRes = fputs($handle, "MAIL FROM:<$sender>\r\n");
$nRes = fputs($handle, "RCPT TO:<$recipient>\r\n");
$nRes = fputs($handle, "DATA\r\n");
$nRes = fputs($handle, "To: $recipient\r\n");
$nRes = fputs($handle, "Subject: $subject\n\n");
$nRes = fputs($handle, "$content\r\n");
$nRes = fputs($handle, ".\r\n");

// Close connection to SMTP server
$nRes = fputs($handle, "QUIT\n");

--------------------------------------------------------------------
[google][/google]

Posted: Fri Dec 17, 2004 1:47 am
by kettle_drum
Split the script up and check that each bit is working. Does it make the connection to the server? You never check to make sure that $handle is a valid resource and that it connected. Try reading some data from the connection to see what the server is sending back to you.

Posted: Fri Dec 17, 2004 10:41 am
by slaher
A server connection is being made. It seems, however, that the server is rejecting all messages. Below is the list of server responses.

Thanks.
-sl
-------------------------------
Server Response : 554 someservername ESMTP not accepting messages

550 5.0.0 Command rejected

500 5.5.1 Command unrecognized: <encoded_username>

500 5.5.1 Command unrecognized: <encoded_passwd>

250 pro20.abac.com Hello hostname [IP-address], pleased to meet you

550 5.0.0 Command rejected

550 5.0.0 Command rejected

550 5.0.0 Command rejected

500 5.5.1 Command unrecognized: "To: my_yahoo_id@yahoo.com"

500 5.5.1 Command unrecognized: "Subject: test subj"

500 5.5.1 Command unrecognized: ""

500 5.5.1 Command unrecognized: "test contents"

-------------------------------------------[/mail_search]

Posted: Fri Dec 17, 2004 11:59 am
by Joe
Why not try port 25 instead (smtp). I see that you are using port 587, protocol esmtp. I do not use yahoo mail myself so I cannot be certain.

Posted: Fri Dec 17, 2004 2:02 pm
by slaher
I tried port 25, and get the same results.

The mail server is actually not yahoo's, but rather our company's external (ISP) mail server. I am just sending the email to my personal yahoo email address. Sorry if that wasn't clear.

Posted: Fri Dec 17, 2004 4:35 pm
by Joe
Why not try using mail()?

Posted: Fri Dec 17, 2004 4:44 pm
by slaher
I was trying using mail() initially, but was getting the message below, so I assumed the server needs authentication. Hence, I switched to the fsocket code reproduced above.

---------
PHP Warning: mail(): SMTP server response: 554 5.7.1 Header forgery attempt - rejected in C:\www\webroot\TEST\sendmail.php on line 74