153
$from = "someonelse@example.com";
$headers = "From:" . $from;
echo mail ("borutflis1@gmail.com" ,"testmailfunction" , "Oj",$headers);

PHP でメールを送信できません。エラーが表示されます: SMTP server response: 530 SMTP authentication is required

確認のために SMTP なしでメールを送信できるという印象を受けました。このメールがフィルターで除外される可能性が高いことはわかっていますが、現時点では問題ありません。

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = someonelse@example.com

これがphp.iniファイル内の設定です。SMTP はどのように設定すればよいですか? 検証を必要としない、または自分でサーバーをセットアップする必要がある SMTP サーバーはありますか?

4

10 に答える 10

195

SMTP 認証が必要なサーバーを介して電子メールを送信する場合は、実際にそれを指定し、ホスト、ユーザー名、およびパスワードを設定する必要があります (デフォルトのポートでない場合は、ポートも 25 に設定する必要があります)。

たとえば、私は通常、これと同様の設定で PHPMailer を使用します。

$mail = new PHPMailer();

// Settings
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com";    // SMTP server example
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username";            // SMTP account username example
$mail->Password   = "password";            // SMTP account password example

// Content
$mail->isHTML(true);                       // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();

PHPMailer の詳細については、https ://github.com/PHPMailer/PHPMailer をご覧ください。

于 2013-01-22T10:46:56.890 に答える
63
<?php
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "YOURMAIL@gmail.com");

$message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail@address.com";

$headers = "From: YOURMAIL@gmail.com";

mail("Sending@provider.com", "Testing", $message, $headers);
echo "Check your email now....&lt;BR/>";
?>

または、詳細については、をお読みください。

于 2013-01-22T11:21:47.913 に答える
12

認証なしで動作する SMTP サーバーがいくつかありますが、サーバーが認証を必要とする場合、それを回避する方法はありません。

PHP の組み込みメール機能は非常に限られています。SMTP サーバーの指定は Windows でのみ可能です。*nix ではmail()、OS のバイナリを使用します。

ネット上の任意の SMTP サーバーにメールを送信したい場合は、SwiftMailerのようなライブラリの使用を検討してください。これにより、たとえば、Google Mail の送信サーバーを使用できるようになります。

于 2013-01-22T10:44:52.627 に答える
0

別のアプローチとして、次のようなファイルを使用できます。

From: Sunday <sunday@gmail.com>
To: Monday <monday@gmail.com>
Subject: Day

Tuesday Wednesday

次のように送信します。

<?php
$a1 = ['monday@gmail.com'];
$r1 = fopen('a.txt', 'r');
$r2 = curl_init('smtps://smtp.gmail.com');
curl_setopt($r2, CURLOPT_MAIL_RCPT, $a1);
curl_setopt($r2, CURLOPT_NETRC, true);
curl_setopt($r2, CURLOPT_READDATA, $r1);
curl_setopt($r2, CURLOPT_UPLOAD, true);
curl_exec($r2);

https://php.net/function.curl-setopt

于 2020-08-03T22:56:49.420 に答える