mail problem
Posted: Thu Dec 16, 2004 6:02 pm
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]
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]