How to send email using phpmailer (phpmailer का उपयोग करके ईमेल कैसे भेजें?) –
- Using phpmailer, send an email message by PHP Code (phpmailer का उपयोग करके, PHP कोड द्वारा ईमेल संदेश भेजें) : code is given bellow –
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.codeloveguru.com'; // Host name
$mail->SMTPAuth = true;
$mail->Username = 'smtp_user_name@codeloveguru.com'; //SMTP username
$mail->Password = 'smtp_user_password'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465; //TCP port
$mail->setFrom('from_mail_id@codeloveguru.com', 'Mailer');
$mail->addAddress('ashok@codeloveguru.net', 'Ashok User');
$mail->addAddress('ramesh@codeloveguru.com');
$mail->addReplyTo('info123@codeloveguru.com', 'Information');
$mail->addCC('cc_mail_id@codeloveguru.com');
$mail->addBCC('bcc_email_id@codeloveguru.com');
$mail->addAttachment('/var/tmp/attachfile.pdf'); //adding attachments
$mail->addAttachment('/tmp/newimage.jpg', 'abc.jpg'); //Optional
$mail->isHTML(true); //send email HTML format
$mail->Subject = 'The mail subject here';
$mail->Body = 'HTML message body here';
$mail->AltBody = 'plain text for non-HTML mail users';
$mail->send();
echo 'The email has been sent successfully';
} catch (Exception $e) {
echo "Email could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>- The bellow PHP codes define the library of PHPMailer (नीचे दिए गए PHP कोड PHPMailer की लाइब्रेरी को परिभाषित करते हैं।).
- This code must be added at top of your script, not inside a function in PHP File (यह कोड आपकी स्क्रिप्ट के शीर्ष पर जोड़ा जाना चाहिए, PHP फ़ाइल में किसी फ़ंक्शन के अंदर नहीं।).
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);- The bellow codes define the HTML format message/ body of email message (नीचे दिए गए कोड ईमेल संदेश के HTML प्रारूप संदेश/मुख्य भाग को परिभाषित करते हैं) –
$mail->isHTML(true); //send email HTML format
$mail->Subject = 'The mail subject here';
$mail->Body = 'HTML message body here';
$mail->AltBody = 'plain text for non-HTML mail users';- The given codes define the attachment files with the email message (दिए गए कोड ईमेल संदेश के साथ अनुलग्नक फ़ाइलों को परिभाषित करते हैं।) –
$mail->addAttachment('/var/tmp/attachfile.pdf'); //adding attachments
$mail->addAttachment('/tmp/newimage.jpg', 'abc.jpg'); //Optional- The $mail->addCC() & $mail->addBCC() codes define the CC and BCC of Email ID ($mail->addCC() और $mail->addBCC() कोड ईमेल आईडी की CC और BCC को परिभाषित करते हैं) –
$mail->addCC('cc_mail_id@codeloveguru.com');
$mail->addBCC('bcc_email_id@codeloveguru.com');How to send email using phpmailer
Tags: Code send email PHP, How to send email using phpmailer, Send email using phpmailer, Using phpmailer send email
