mail() 関数は、スクリプトから簡単にメールを直接送信できるようにするのに役立ちます。通常は 5 つのパラメータを受け入れますが、そのうちの最初の 3 つだけが必須であり、他の 2 つのパラメータはオプションであり、すべてのパラメータが mail() 関数の括弧内に記載されている場合は必須ではありません。これは、必要に応じていつでも何らかのフォームなどを使用して Web サイトやブログからメールを直接送信するのに役立ちます。これは、PHP スクリプトからの電子メールの送信に役立つ PHP プログラミング言語の組み込み関数です。重要なタスクやイベントについてユーザーに通知する場合、費用対効果が高くなります。
無料ソフトウェア開発コースを始めましょう
Web 開発、プログラミング言語、ソフトウェア テスト、その他
構文とパラメータ
以下は構文です
mail(to1, subject1, message1, headers1, parameters1);
mail() 関数のパラメータの説明:
- mail() 関数の to1 パラメータ: PHP プログラミング言語の mail() 関数の「to1」パラメータは必須フィールドです。メールの受信者を指定するのに役立ちます。
- mail() 関数の subject1 パラメータ: PHP プログラミング言語の mail() 関数の「subject1」パラメータも必須フィールドです。メールの件名を指定するのに役立ちます。このパラメータには、改行文字が含まれる場合と含まれない場合があります。
- mail() 関数の message1 パラメータ: PHP プログラミング言語の mail() 関数の「message1」パラメータも、上記 2 つのパラメータと同様に必須フィールドです。送信されるメッセージを定義するのに役立ちます。その各行は LF (n) で区切る必要があります。各行は 70 文字を超えてはなりません。 Windows では、メッセージ内の特定の行の先頭に FULLSTOP が見つかった場合、それが削除される可能性があります。この種の問題を解決するには、終点文字を二重ドット文字「..」に置き換える必要があります。
- mail() 関数の headers1 パラメータ: PHP 言語の headers1 パラメータはオプションのフィールドですが、Cc、From、Bcc 関数などの追加ヘッダーを指定するのに役立ちます。追加ヘッダーの一部は CRLF – (rn) で区切られます。 EMAIL の送信処理中に、From ヘッダーが含まれる場合があります。これは、この headers1 パラメータまたは PHP.INI 形式ファイルで設定できます。
- mail() 関数のparameters1 パラメータ: mail 関数のparameters1 パラメータはオプションです。このパラメータは追加パラメータを指定します。これは、電子メール送信プログラムに追加パラメータを指定するのに役立ちます。この設定は、–f send mail オプションを使用するときにエンベロープ送信者のアドレスに設定されます。
PHP では mail() 関数はどのように動作しますか?
PHP プログラミング言語の mail() 関数は、PHP スクリプト自体から直接メールを送信することを支援するだけで機能します。 PHP 4 以降のバージョンで動作します。 PHP 4 バージョンより前のバージョンでは、この mail() は機能しないため、PHP バージョンが PHP 4 バージョンより前の場合は mail() 関数を試行しないでください。これは、アドレスパラメータのハッシュ値を返すことによって機能します。ただし、メールの配信が受け入れられたとしても、そのメールが実際に受信または送信されたことを意味するわけではないことに注意する必要があります。
PHP 4.0.5 バージョンには、parameter1 パラメーターが追加されています。 PHP 4.2.3 の PHP バージョンでは、セーフ モードでは、parameter1 パラメーターが無効になります。 Windows OS 上の PHP 4.3.0 バージョンの場合Cc、Bcc、From、Date などのカスタム ヘッダーを受け入れますが、大文字と小文字は区別されません。 PHP 5.4 バージョンでは、ヘッダー パラメーターの目的のみにヘッダー インジェクション保護が追加されています。 PHP 7.2 バージョンでは、headers1 パラメータも配列を受け入れるようになります。
例
以下に挙げる例を示します:
例 #1
この例では、PHP プログラミング言語の mail() 関数を実装します。ここでは、最初に PHP タグが作成され、その中にいくつかの値を含むいくつかの変数が作成されます。最初に、メールの送信に必要な特定のメール/Gmail アドレスである文字列値を使用して「to_email1」が作成されます。次に、件名として表示する文字列コンテンツを含む「subject1」変数が作成され、次にメッセージ変数が作成され、重要なメッセージ テキスト情報/その他が割り当てられます。 to_email1アドレスの人に情報を指定することです。次に、header1 変数が作成されます。次に、メインの PHP 関数 mail() が使用されます。ここでは、mail() 関数内に 4 つのパラメータが含まれています。この関数は、PHP スクリプト自体を使用してメールを送信する場合に役立ちます。
コード:
<?php $to_email1 = 'name1 @ company .com'; $subject1 = 'Testing the PHP Mail'; $message1 = 'This mail is sent using the PHP mail function'; $headers1 = 'From: noreply @ company .com'; mail($to_email1,$subject1,$message1,$headers1); ?>
出力:
Example #2
This is the example of implementing the custom functions which helps in sending the secure mail to a specific person only with the help of the mail() function inside the PHP script. Here at first a function with some fields are created along with the condition statements. Then “to_email1” variable is created with some email address. Then subject1, messages, and headers1 variables are created. Based on the IF ELSE conditions and the mail() function along with the HTML display elements the program will run and the mail will be sent to the specified email person or other but the PHP.INI file settings should be perfect or use any online compiler if possible.
Code:
<?php functionsanitize_my_email($field1) { $field1 = filter_var($field1, FILTER_SANITIZE_EMAIL); if (filter_var($field1, FILTER_VALIDATE_EMAIL)) { return true; } else { return false; } } $to_email1 = 'name @ company .com'; $subject1 = 'Testing PHP Mail'; $message1 = 'This mail is sent using the PHP mail '; $headers1 = 'From: noreply @ company. com'; //check whether the email address is invalid or not $secure_check $secure_check1 = sanitize_my_email($to_email1); if ($secure_check1 == false) { echo "Invalid input"; } else { //send email mail($to_email1, $subject1, $message1, $headers1); echo "This email is now sent using the PHP Mail"; } ?>
Output:
Example #3
This is the example of implementing the PHP mail() function without using the header1 parameter inside of the mail() function of the PHP Programming Language. It is a simple mail but the header1 parameter is not used.
Code:
<?php $to1 = '[email protected]'; $subject1 = 'The Marriage Proposal'; $message1 = 'Hi Radha, will you marry me? Say Yes or No'; $from1 = '[email protected]'; // Sending email if(mail($to1, $subject1, $message1)){ echo 'Now Your mail will be sent automatically and successfully.'; } else{ echo 'Now it is Unable to send the email/gmail. Please try again.'; } ?>
Output:
Example #4
This is the example of implementing the PHP mail() function in order to send an attachment file along with the mail. Here at first HTML form is created for some variable values and to get the attachment file. After clicking the submit button the PHP mail() function works with the help of the PHP mail function code. Then the output text will be displayed as shown in the output section below.
HTML File Code:
PHP File Code:
<?php if($_POST['button'] &&isset($_FILES['attachment1'])) { $from_email = '[email protected]'; //from mail, sender email addrress $recipient_email = '[email protected]'; //recipient email addrress //Load POST data from HTML form $sender_name1 = $_POST["sender_name1"] //sender name1 $reply_to_email = $_POST["sender_email1"] //sender email1, it will be used in "reply-to" header $subject1 = $_POST["subject1"] //subject1 for the email $message1 = $_POST["message1"] //message1 body1 of the email //Get uploaded file data using $_FILES array $tmp_name = $_FILES['my_file']['tmp_name']; // Now get the temporary file name1 of the file on the server $name = $_FILES['my_file']['name']; // Now get the name of the file1 $size = $_FILES['my_file']['size']; // Now get size of the file1 for size validation $type = $_FILES['my_file']['type']; // Now get type of the file1 $error = $_FILES['my_file']['error']; // Now get the error (if any) //It is a validating form field which helps in attaching the file if($file_error> 0) { die('Upload error or No files uploaded'); } //It is like reading from a specific uploaded file and also the base64_encode content1 $handle1 = fopen($tmp_name, "r"); // Now setting the file handle1 only for reading the file $content1 = fread($handle1, $size); // Now reading the file fclose($handle1); // Now close upon completion $encoded_content11 = chunk_split(base64_encode($content1)); $boundary1 = md5("random"); // Now defining the boundary1 with a md5 hashed value //Now header $headers1 = "MIME-Version: 1.0\r\n"; // Now Defining the MIME version $headers1 .= "From:".$from_email."\r\n"; // Now the Sender Email $headers1 .= "Reply-To: ".$reply_to_email."\r\n"; // Now Email addrress to reach back $headers1 .= "content1-Type: multipart/mixed;\r\n"; // Now Defining content1-Type $headers1 .= "boundary1 = $boundary1\r\n"; // Now Defining the boundary1 //Now this is about plain text $body1 = "--$boundary1\r\n"; $body1 .= "content1-Type: text/plain; charset=ISO-8859-1\r\n"; $body1 .= "content1-Transfer-Encoding: base64\r\n\r\n"; $body1 .=chunk_split(base64_encode($message1)); //NOw attachment1 $body1 .= "--$boundary1\r\n"; $body1 .="content1-Type: $file_type; name=".$file_name."\r\n"; $body1 .="content1-Disposition: attachment1; filename=".$file_name."\r\n"; $body1 .="content1-Transfer-Encoding: base64\r\n"; $body1 .="X-attachment1-Id: ".rand(1000, 99999)."\r\n\r\n"; $body1 .= $encoded_content11; // NOw Attaching the encoded file with email $sentMailResult1 = mail($recipient_email, $subject1, $body1, $headers1); if($sentMailResult1 ) { echo "This mail is sent using the PHP mail function"; // Now it will be printed only if the file is going to be sent successfully unlink($name); // Now deleting the file just after the attachment1 is sent. } else { die("Sorry attachment mail not sent"); } } ?>
Output of HTML Code:
Output of PHP Code:
Conclusion
We hope you learned what is the definition of PHP mail() function along with its syntax and explanation of the parameter of the mail() function, How the mail() function works in PHP along with various examples to under mail() concept better and so easily.
以上がPHPメール()の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン
