PHPからEメールを送信

PHPからEメールを送信
<?php
    $to = "[email protected]";
    $subject = "My subject";
    $txt = "Hello world!";
    $headers = "From: [email protected]";

    mail($to,$subject,$txt,$headers);
    var_dump($mail);
?>

電子メールを送信しようとしています。うまくいかず、理由がわかりません。私もエラーは発生しません。メールを受信できませんでした。他のメールアドレスも試してみました。 lampp/xamppのファイルを編集する必要がありますか?

var_dumpいつも戻ってきてbool(false)

コードを少し変更しました。php.ini

[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 = [email protected]

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header=On

; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log =

私にも同じ問題がありますが、

ベストアンサー1

PHPメール機能を使用するには、いくつかのバックエンド操作、つまりSMTPサービスを正しく設定する必要があります。 php.iniの[メール機能]セクションで関連する設定を確認し、上記の正しく設定されたSMTPサービスにアクセスできるように設定する必要があります。

デフォルトは localhost なので、localhost に SMTP を設定しない場合や、インターネットへのメール転送を設定しないと、PHP メール機能は機能しません。

おすすめ記事