पीएचपी मेल () समारोह
उदाहरण
एक साधारण ईमेल भेजें:
<?php
// the message
$msg = "First line of text\nSecond line of text";
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
// send email
mail("[email protected]","My subject",$msg);
?>
परिभाषा और उपयोग
मेल () फ़ंक्शन आपको स्क्रिप्ट से सीधे ईमेल भेजने की अनुमति देता है।
वाक्य - विन्यास
mail(to,subject,message,headers,parameters);
पैरामीटर मान
Parameter | Description |
---|---|
to | Required. Specifies the receiver / receivers of the email |
subject | Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters |
message | Required. Defines the message to be sent. Each line should be separated with a LF (\n).
Lines should not exceed 70 characters.
Windows note: If a full stop is found on the beginning of a line in the message, it might be removed. To solve this problem, replace the full stop with a double dot: |
headers | Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).
Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file. |
parameters | Optional. Specifies an additional parameter to the sendmail program (the one defined in the sendmail_path configuration setting). (i.e. this can be used to set the envelope sender address when using sendmail with the -f sendmail option) |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | पता पैरामीटर का हैश मान देता है , या विफलता पर FALSE देता है। नोट: ध्यान रखें कि भले ही ईमेल डिलीवरी के लिए स्वीकार कर लिया गया हो, इसका मतलब यह नहीं है कि ईमेल वास्तव में भेजा और प्राप्त किया गया है! |
---|---|
पीएचपी संस्करण: | 4+ |
पीएचपी चेंजलॉग: | PHP 7.2: हेडर पैरामीटर भी एक सरणी स्वीकार करता है PHP 5.4: हेडर पैरामीटर के लिए जोड़ा गया हेडर इंजेक्शन सुरक्षा । PHP 4.3.0: (केवल विंडोज़) सभी कस्टम हेडर (जैसे प्रेषक, प्रतिलिपि, गुप्त प्रतिलिपि और दिनांक) समर्थित हैं, और केस-संवेदी नहीं हैं। PHP 4.2.3: पैरामीटर पैरामीटर सुरक्षित मोड में अक्षम है PHP 4.0.5: पैरामीटर पैरामीटर जोड़ा गया था |
और ज्यादा उदाहरण
अतिरिक्त हेडर के साथ एक ईमेल भेजें:
<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
?>
एक HTML ईमेल भेजें:
<?php
$to = "[email protected], [email protected]";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to,$subject,$message,$headers);
?>
❮ पूर्ण PHP मेल संदर्भ