![]() You should now be ready to use PHPMailer! Localization See the mailing list example for further guidance. when sending to a mailing list), you may need to clear the recipient list to avoid sending duplicate messages. You'll find plenty to play with in the examples folder, which covers many common scenarios including sending through Gmail, building contact forms, sending to mailing lists, and more. $mail-> AltBody = 'This is the body in plain text for non-HTML mail clients' Įcho " Message could not be sent. $mail-> Body = 'This is the HTML message body in bold!' $mail-> addCC( addBCC( $mail-> addAttachment( '/var/tmp/') //Add attachments $mail-> addAttachment( '/tmp/image.jpg', 'new.jpg') //Optional name //Content $mail-> isHTML( true) //Set email format to HTML $mail-> Subject = 'Here is the subject' $mail-> addAddress( 'Joe User') //Add a recipient $mail-> addAddress( //Name is optional $mail-> addReplyTo( 'Information') If you want to use the Gmail XOAUTH2 authentication class, you will also need to add a dependency on the league/oauth2-client package in your composer.json.Īlternatively, if you're not using Composer, youĬan download PHPMailer as a zip file, (note that docs and examples are not included in the zip file), then copy the contents of the PHPMailer folder into one of the include_path directories specified in your PHP configuration and load each class file manually: SMTPDebug = SMTP:: DEBUG_SERVER //Enable verbose debug output $mail-> isSMTP() //Send using SMTP $mail-> Host = '' //Set the SMTP server to send through $mail-> SMTPAuth = true //Enable SMTP authentication $mail-> Username = //SMTP username $mail-> Password = 'secret' //SMTP password $mail-> SMTPSecure = PHPMailer:: ENCRYPTION_SMTPS //Enable implicit TLS encryption $mail-> Port = 465 //TCP port to connect to use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` //Recipients $mail-> setFrom( 'Mailer') Note that the vendor folder and the vendor/autoload.php script are generated by Composer they are not part of PHPMailer. ![]() Or run composer require phpmailer/phpmailer Just add this line to your composer.json file: "phpmailer/phpmailer": "^6.8.0 " PHPMailer is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install PHPMailer. Please read LICENSE for information on the software availability and distribution. This software is distributed under the LGPL 2.1 license, along with the GPL Cooperation Commitment. You should look at before rolling your own. Please don't be tempted to do it yourself – if you don't use PHPMailer, there are many other excellent libraries that Be aware though, that the mail() function should be avoided when possible it's both faster and safer to use SMTP to localhost. The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD, and macOS platforms, however, Windows usually doesn't include a local mail server PHPMailer's integrated SMTP client allows email sending on all platforms without needing a local mail server. There are myriad overlapping (and conflicting) standards, requiring tight adherence to horribly complicated formatting and encoding rules – the vast majority of code that you'll find online that uses the mail() function directly is just plain wrong, if not unsafe! However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments.įormatting email correctly is surprisingly difficult. The only PHP function that supports this directly is mail(). Many PHP developers need to send email from their code. Compatible with PHP 5.5 and later, including PHP 8.2.Protects against header injection attacks.Validates email addresses automatically.SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over SMTPS and SMTP+STARTTLS transports.Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings.Multipart/alternative emails for mail clients that do not read HTML email.Send emails with multiple To, CC, BCC, and Reply-to addresses.Integrated SMTP support – send without a local mail server.Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more.Probably the world's most popular code for sending email from PHP!. ![]() ![]() PHPMailer – A full-featured email creation and transfer class for PHP
0 Comments
Leave a Reply. |