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]
mail problem
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
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]
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]
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
---------
PHP Warning: mail(): SMTP server response: 554 5.7.1 Header forgery attempt - rejected in C:\www\webroot\TEST\sendmail.php on line 74