私は解決策を探していましたが、いくつかの同様のスレッドを確認した後でも、自分の状況に合ったものを見つけることができませんでした.
テスト スクリプトを実行すると、次の出力が得られます。
string(33) "Failed to Initiate Authentication"
問題のトラブルシューティングを何度か試みた後、エラーの原因がわかりません。
これは私のコードです:
<?php
$SMTP_SERVER = 'relay-hosting.secureserver.net';
$SMTP_PORT = 25;
$SMTP_USERNAME = 'no-reply@website.com';
$SMTP_PASSWORD = 'password';
$SMTP_FROM = 'no-reply@website.com';
function smtpmail($to, $subject, $message, $headers = ''){
// set as global variable
global $SMTP_SERVER, $SMTP_PORT, $SMTP_USERNAME, $SMTP_PASSWORD, $SMTP_FROM;
// get From address
if ( $headers && preg_match("/From:.*?[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+.*/", $headers, $froms) ){
preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+/", $froms[0], $fromarr);
$from = $fromarr[0];
}else{
$from = $SMTP_FROM;
$headers = 'From: '.$from."\r\n".$headers;
}
// Clean some of this stuff up...
// escape the message
$message = str_replace("\n.", "\n..", $message);
// also escape any leading period
if($message[0] == '.'){
$message = '.'. $message;
}
// escape the subject
$subject = str_replace( array("\r", "\n"), '', $subject );
// escape the recipient
$to = str_replace( array("\r", "\n"), '', $to );
// making sure not to send a zero, 'null', or etc. ambiguity ftw..</sarcasm>
if(!$headers) $headers = '';
// Open an SMTP connection
$cp = fsockopen ($SMTP_SERVER, $SMTP_PORT, &$errno, &$errstr, 1);
if (!$cp)
return "Failed to even make a connection";
$res=fgets($cp,256);
if(substr($res,0,3) != "220") return "Failed to connect";
// Say hello...
fputs($cp, "HELO ".$SMTP_SERVER."\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "Failed to Introduce";
// perform authentication
fputs($cp, "auth login\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "334") return "Failed to Initiate Authentication";
fputs($cp, base64_encode($SMTP_USERNAME)."\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "334") return "Failed to Provide Username for Authentication";
fputs($cp, base64_encode($SMTP_PASSWORD)."\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "235") return "Failed to Authenticate";
// Mail from...
fputs($cp, "MAIL FROM: <$from>\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "MAIL FROM failed";
// Rcpt to...
fputs($cp, "RCPT TO: <$to>\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "RCPT TO failed";
// Data...
fputs($cp, "DATA\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "354") return "DATA failed";
// Send To:, Subject:, other headers, blank line, message, and finish
// with a period on its own line (for end of message)
fputs($cp, "To: $to\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "Message Body Failed";
// ...And time to quit...
fputs($cp,"QUIT\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "221") return "QUIT failed";
return true;
}
//var_dump(smtpmail('mramonster@hotmail.com', 'email subject', ".\r\njust a: (message) 'that'\nwill <a href='http://www.google.com/'>hopefully</a> %get #through\r\n.\r\nsomething","From: test@example.com\r\n"));
?>
ユーザー名、サーバー、パスワード、電子メールなどを再確認しましたが、エラーの原因がわかりません。
注: 「no-reply@website.com」や「password」は資格情報として使用しません。