BCA / B.Tech 8 min read

Send Email By PHP in Hindi

Sending Email By PHP in Hindi |  PHP में ईमेल भेजना हिंदी में :


  • PHP में ईमेल भेजना एक सरल प्रक्रिया है। इसे करने के लिए PHP में इनबिल्ट mail() फंक्शन का उपयोग किया जा सकता है। 
  • साथ ही, अधिक सुरक्षित और उन्नत तरीके के लिए, आप PHPMailer लाइब्रेरी का भी उपयोग कर सकते हैं।
Send Email By PHP in Hindi

 यहां हम दोनों तरीके विस्तार से समझाएंगे।

PHP का mail() फंक्शन इस्तेमाल करके ईमेल भेजना:

यह एक सरल और आसान तरीका है। इस फंक्शन का उपयोग सीधे ईमेल भेजने के लिए किया जा सकता है।

उदाहरण:

// रिसीवर का ईमेल पता

// ईमेल का सब्जेक्ट
$subject = "यह एक टेस्ट ईमेल है";

// ईमेल का संदेश
$message = "नमस्ते,\n\nयह ईमेल PHP का उपयोग करके भेजा गया है।";

// हेडर्स (From और Reply-To)
$headers = "From: [email protected]\r\n" .
           "Reply-To: [email protected]\r\n" .
           "X-Mailer: PHP/" . phpversion();

// ईमेल भेजें
if (mail($to, $subject, $message, $headers)) {
    echo "ईमेल सफलतापूर्वक भेजा गया!";
} else {
    echo "ईमेल भेजने में समस्या हुई!";
}
?>

ध्यान दें:
  • mail() फंक्शन केवल तभी काम करता है जब सर्वर पर मेल सर्विस सही तरीके से कॉन्फ़िगर हो।
  • इसका उपयोग साधारण कार्यों के लिए किया जाता है, लेकिन यह अत्यधिक विश्वसनीय नहीं होता।

PHPMailer का उपयोग करके ईमेल भेजना:

PHPMailer एक पॉपुलर PHP लाइब्रेरी है जो सुरक्षित और बेहतर तरीके से ईमेल भेजने में मदद करती है। इसका उपयोग SMTP (Simple Mail Transfer Protocol) के माध्यम से किया जा सकता है।

चरण 1: PHPMailer इंस्टॉल करें
आप composer का उपयोग करके इसे इंस्टॉल कर सकते हैं:

composer require phpmailer/phpmailer

चरण 2: कोड लिखें

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// PHPMailer को लोड करें
require 'vendor/autoload.php';

// PHPMailer का एक ऑब्जेक्ट बनाएं
$mail = new PHPMailer(true);

try {
    // SMTP सेटअप
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com'; // SMTP सर्वर
    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]'; // अपना ईमेल
    $mail->Password = 'your-email-password'; // अपना पासवर्ड
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port = 587;

    // ईमेल सेटअप
    $mail->setFrom('[email protected]', 'Your Name');
    $mail->addAddress('[email protected]', 'Receiver Name'); // रिसीवर
    $mail->Subject = 'यह एक PHPMailer टेस्ट ईमेल है';
    $mail->Body = 'नमस्ते,\n\nयह ईमेल PHPMailer का उपयोग करके भेजा गया है।';

    // ईमेल भेजें
    $mail->send();
    echo "ईमेल सफलतापूर्वक भेजा गया!";
} catch (Exception $e) {
    echo "ईमेल भेजने में समस्या हुई। Error: {$mail->ErrorInfo}";
}
?>
ध्यान दें:

  • SMTP इस्तेमाल करने के लिए सही क्रेडेंशियल्स (जैसे Gmail के लिए यूज़रनेम और पासवर्ड) आवश्यक हैं।
  • Gmail के लिए, आपको "Less Secure App Access" को चालू करना पड़ सकता है, या API Key का उपयोग करना होगा।
किसे कब उपयोग करें?

  • mail() फंक्शन: यदि आपका ईमेल सिस्टम सिंपल और बेसिक है।
  • PHPMailer: यदि आपको सुरक्षित और विश्वसनीय तरीके से ईमेल भेजने की आवश्यकता है।
  • अगर आपको PHPMailer के सेटअप में कोई समस्या आती है, तो आप मुझसे पूछ सकते हैं!

In this Chapter

Send Email By PHP in Hindi
Introduction to PHP in Hindi | PHP का परिचय हिंदी में
Flow Control Statements in Hindi | PHP में फ़्लो कंट्रोल स्टेटमेंट्स हिंदी में
Embedding PHP in Webpages in Hindi | वेबपेज में PHP को एम्बेड करना
Use Of MYSQL in PHP in Hindi | MySQL का PHP में उपयोग हिंदी में
How to Configure our framework in Hindi | फ्रेमवर्क को कॉन्फ़िगर करना हिंदी में
Difference between PHP and HTML in Hindi
Advance Features PHP in Hindi | PHP के एडवांस फीचर्सस हिंदी में
Expression in PHP in Hindi | PHP में एक्सप्रेशन हिंदी में
Juggling Expression in PHP in Hindi | PHP में जुगलिंग हिंदी में
Comments in PHP in Hindi | PHP में Comments हिंदी में
Whitespace in Hindi | Whitespace हिंदी में
Difference Between Echo and Print in PHP in Hindi | echo और print में अंतर हिंदी में
Line & Paragraph Brakes in PHP in Hindi | PHP में लाइन और पैराग्राफ ब्रेक्स हिंदी में
Date & Time Function of PHP in Hindi
Array Functions in Hindi
PHP Stack and Queue in Hindi
RAND Function in Hindi
String Functions in Hindi
Sorting in Hindi
PHP Form in Hindi
What is Form Tag in Hindi | Form टैग क्या है
PHP Elements in Hindi
Session & Cookies in Hindi
File Uploading in Hindi
Regular Expression in Hindi
Error Handling in PHP in Hindi