【解決方法】HTML フォームからメッセージを送信する

[ad_1]

I am working on sending message from HTML form with the following PHP code for its functionality:
<?php
phpinfo();
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
function ShutdownHandler() {
    if (is_array($error = error_get_last())) {
        return (call_user_func_array('ErrorHandler', $error));
    };
    return (TRUE);
};
register_shutdown_function('ShutdownHandler');
// ----------------------------------------------------------------------------------------------------
// - Error Handler
// ----------------------------------------------------------------------------------------------------
function ErrorHandler($type, $message, $file, $line) {
    $_ERRORS = Array(0x0001 => 'E_ERROR', 0x0002 => 'E_WARNING', 0x0004 => 'E_PARSE', 0x0008 => 'E_NOTICE', 0x0010 => 'E_CORE_ERROR', 0x0020 => 'E_CORE_WARNING', 0x0040 => 'E_COMPILE_ERROR', 0x0080 => 'E_COMPILE_WARNING', 0x0100 => 'E_USER_ERROR', 0x0200 => 'E_USER_WARNING', 0x0400 => 'E_USER_NOTICE', 0x0800 => 'E_STRICT', 0x1000 => 'E_RECOVERABLE_ERROR', 0x2000 => 'E_DEPRECATED', 0x4000 => 'E_USER_DEPRECATED');
    if (!@is_string($name = @array_search($type, @array_flip($_ERRORS)))) {
        $name = 'E_UNKNOWN';
    };
    return (print (@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
};
$old_error_handler = set_error_handler("ErrorHandler");
//get data from form
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  //echo($_POST)  ;
  //echo gettype($_POST) . "hello";
$name =$_POST['name'];
echo $name;
$email =$_POST['email'];
echo $email;
$message = $_POST['message'];
echo $message;
$subject =  $_POST['subject'];
echo $subject;

$fromaddress = "From: abhinavkishorem9@gmail.com";
$toaddress='to:'.$email;
//$headers = "MIME-Version: 1.0\r\n";
//$headers = "Content-type: text/html\r\n";
//$headers = 'From: index.html' . "\r\n" . 'Reply-To: abhinavkishorem9@gmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
if (mail($toaddress, $subject, $message,$toaddress )) {
    echo "Sent";
} else {
    echo "Failed";
}
}
?>



                                                                                                                                                                                                                                                     
Bottlenecks/Problems: The thing is I put the information in the form, and everytime I get the message "Failed". I have looked for this in Google about this. I thought it might be due to bad request error and tried to look into it in Code Project for solutions from fellow programmers. But this bottleneck/problem still persists. 

私が試したこと:

The thing is I put the information in the form, and everytime I get the message "Failed". I have looked for this in Google about this. I thought it might be due to bad request error and tried to look into it in Code Project for solutions from fellow programmers. But this bottleneck/problem still persists.

解決策 1

ドキュメントを読む: PHP: メール – マニュアル[^]

4 番目のパラメーターはオプションであり、おそらく ToAddress を繰り返さないでください。
他に確認すべきことは、$message の行の長さです。文書によると、行は最大 70 文字である必要があります。リンクには、これを保証するコードが含まれています。

[ad_2]

コメント

タイトルとURLをコピーしました