Lỗi notice undefined property stdclass icon in trong joomla năm 2024

PHPMailer is a highly popular, actively developed email-sending library for PHP hosting. And it’s open source.

Below, we’ll give you a quick and easy example of a working script you can use in your local development environment or live on your InMotion Hosting server.

For more information about PHPMailer, or to contribute, check out the PHPMailer GitHub page. Looking for a top-notch PHP web host? You’ve come to the right place.

Install the PHPMailer Dependencies

You may be excited to get this code into your app, but first you need to make sure you’ve installed the necessary code library.

For this example, we’re going to be installing PHPMailer with Composer, since that is the preferred method for a great many PHP developers.

composer require phpmailer/phpmailer

That’s it! If you don’t have one already, composer will create your “vendor” directory and populate your autoload file.

Add The Code to Your App

Now is the fun part. But before running this code, make sure to change some of the example text we used below with your own information.

SampleReplace with[email protected]Your sender email addressmail.example.comYour SMTP server name‘password’The sender email password[email protected]The recipient email addressName of senderDesired sender nameName of recipientDesired recipient name

Once you have switched out the example text, make sure to select the right development mode. This code can be used on your local server or a live production environment.

For local developmentkeep the $developmentMode variable set to true`For live serverchange the $developmentMode` variable to false

We’re ready to begin.

[email protected]'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $developmentMode = true; $mailer = new PHPMailer($developmentMode); try {

$mailer->SMTPDebug = 2;
$mailer->isSMTP();
if ($developmentMode) {
$mailer->SMTPOptions = [
    'ssl'=> [
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
    ]
];
}
$mailer->Host = 'mail.example.com';
$mailer->SMTPAuth = true;
$mailer->Username = '[[email protected]](https://www.inmotionhosting.com/cdn-cgi/l/email-protection)';
$mailer->Password = 'password';
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;
$mailer->setFrom('[[email protected]](https://www.inmotionhosting.com/cdn-cgi/l/email-protection)', 'Name of sender');
$mailer->addAddress('[[email protected]](https://www.inmotionhosting.com/cdn-cgi/l/email-protection)', 'Name of recipient');
$mailer->isHTML(true);
$mailer->Subject = 'PHPMailer Test';
$mailer->Body = 'This is a SAMPLE email sent through PHPMailer';
$mailer->send();
$mailer->ClearAllRecipients();
echo "MAIL HAS BEEN SENT SUCCESSFULLY";
} catch (Exception $e) {
echo "EMAIL SENDING FAILED. INFO: " . $mailer->ErrorInfo;
} ?>

Source: MyPHPnotes

A note about the ?> tag

In PHP, the ?> tag at the end of a file is optional and can be omitted. The ?> tag denotes the end of the PHP code block and signifies that the parser should switch back to HTML mode. Including the ?> tag is necessary only when there is additional non-PHP code or HTML following the PHP block.

Here are a few scenarios to help you understand when to include or exclude the ?> tag:

Pure PHP code

If your file contains only PHP code and does not include any HTML or non-PHP code after the closing tag, it is recommended to exclude the ?> tag. Omitting it helps to avoid any accidental whitespace or line breaks after the closing tag, which could unintentionally be sent to the browser.

Mix of PHP and HTML code

When your file contains both PHP and HTML code, it is generally best to exclude the ?> tag at the end of the PHP sections. This prevents any accidental output of whitespace or line breaks to the browser.

HTML code here >

PHP code followed by non-PHP code

If your PHP code is followed by non-PHP code, such as JavaScript or plain text, you should include the ?> tag after the PHP code block and before the non-PHP code.

Remember, the inclusion or exclusion of the ?> tag is a matter of preference and coding style. However, it is important to maintain consistency throughout your codebase to ensure readability and minimize any potential issues.


Well done! You’ve completed this tutorial. Now, if you have filled in all the correct data, you should be able to run this script in your browser and send mail to the recipient.