PHP code example of lianhua / email
1. Go to this page and download the library: Download lianhua/email library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lianhua / email example snippets
$email = new \Lianhua\Email\Email();
// Set messages
$email->setMessage("Welcome!");
$email->setAlternateContent("Welcome, screen reader user");
$email->setSubject("Welcome message");
// Get messages
$email->getMessage(); // "Welcome!"
$email->getAlternateContent(); // "Welcome, screen reader user"
$email->getSubject(); // "Welcome message"
$address = new \Lianhua\Email\EmailAddress("[email protected] ", "Recipient Name");
// Set addresses
$email->setFrom($address);
$email->setReply($address);
$email->addTo($address);
$email->addCc($address);
$email->addBcc($address);
// Get addresses
$email->getFrom(); // $address
$email->getReply(); // $address
$email->getTo(); // [$address]
$email->getCc(); // [$address]
$email->getBcc(); // [$address]
$email->clearTo();
$email->clearCc();
$email->clearBcc();
// Add attachments
$email->addAttachment("/tmp/A.pdf");
$email->addAttachment("/tmp/B.pdf");
// Get attachments
$email->getAttachments(); // ["/tmp/A.pdf", "/tmp/B.pdf"]
// Delete attachments
$email->clearAttachments();
// Add headers
$email->addHeader("X-HEADER", "WELCOME");
$email->addHeader("X-HEADER-2", "BIENVENUE");
// Get headers
$email->getHeaders(); // ["X-HEADER" => "WELCOME", "X-HEADER-2" => "BIENVENUE"]
// Delete headers
$email->clearHeaders();
// Set parameter
$email->setCheckDns(true);
// Add address
$email->addTo(new \Lianhua\Email\EmailAddress("[email protected] ")); // Valid
$email->addTo(new \Lianhua\Email\EmailAddress("[email protected] ")); // Not valid
$email->addTo(new \Lianhua\Email\EmailAddress("[email protected] ")); // \Lianhua\Email\Email::NO_ERRORS
$email->addTo(new \Lianhua\Email\EmailAddress("test.google.com")); // \Lianhua\Email\Email::ERROR_EMAIL_FORMAT
// If you enabled DNS check
$email->addTo(new \Lianhua\Email\EmailAddress("[email protected] ")); // \Lianhua\Email\Email::ERROR_EMAIL_DNS_CHECK
// Add attachments
$email->addAttachment("/tmp/A.pdf"); // \Lianhua\Email\Email::NO_ERRORS
$email->addAttachment("/tmp/kjbfkkqsd"); // \Lianhua\Email\Email::ERROR_FILE_NOT_FOUND
$email->addAttachment("/tmp"); // \Lianhua\Email\Email::ERROR_FILE_IS_DIRECTORY