Created
October 29, 2021 14:11
-
-
Save topmask/c574c2e2081c9d5e5c5f112cd77a5d11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$mail->SMTPOptions = array( | |
'ssl' => array( | |
'verify_peer' => false, | |
'verify_peer_name' => false, | |
'allow_self_signed' => true | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Import PHPMailer classes into the global namespace | |
// These must be at the top of your script, not inside a function | |
use PHPMailer\PHPMailer\PHPMailer; | |
use PHPMailer\PHPMailer\SMTP; | |
use PHPMailer\PHPMailer\Exception; | |
// Load Composer's autoloader | |
require 'vendor/autoload.php'; | |
// Instantiation and passing `true` enables exceptions | |
$mail = new PHPMailer(true); | |
try { | |
//Server settings | |
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output | |
$mail->isSMTP(); // Send using SMTP | |
$mail->Host = 'smtp1.example.com'; // Set the SMTP server to send through | |
$mail->SMTPAuth = true; // Enable SMTP authentication | |
$mail->Username = 'user@example.com'; // SMTP username | |
$mail->Password = 'secret'; // SMTP password | |
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged | |
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above | |
//Recipients | |
$mail->setFrom('from@example.com', 'Mailer'); | |
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient | |
$mail->addAddress('ellen@example.com'); // Name is optional | |
$mail->addReplyTo('info@example.com', 'Information'); | |
$mail->addCC('cc@example.com'); | |
$mail->addBCC('bcc@example.com'); | |
// Attachments | |
$mail->addAttachment('/var/tmp/file.tar.gz'); // 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->Body = 'This is the HTML message body <b>in bold!</b>'; | |
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; | |
$mail->send(); | |
echo 'Message has been sent'; | |
} catch (Exception $e) { | |
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enable WP_DEBUG mode | |
define( 'WP_DEBUG', true ); | |
// Enable Debug logging to the /wp-content/debug.log file | |
define( 'WP_DEBUG_LOG', true ); | |
// Disable display of errors and warnings | |
define( 'WP_DEBUG_DISPLAY', false ); | |
@ini_set( 'display_errors', 0 ); | |
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files) | |
define( 'SCRIPT_DEBUG', true ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Upstream to abstract backend connection(s) for php | |
upstream php { | |
server unix:/tmp/php-cgi.socket; | |
server 127.0.0.1:9000; | |
} | |
server { | |
## Your website name goes here. | |
server_name domain.tld; | |
## Your only path reference. | |
root /var/www/wordpress; | |
## This should be in your http block and if it is, it's not needed here. | |
index index.php; | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location / { | |
# This is cool because no php is touched for static content. | |
# include the "?$args" part so non-default permalinks doesn't break when using query string | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~ \.php$ { | |
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini | |
include fastcgi_params; | |
fastcgi_intercept_errors on; | |
fastcgi_pass php; | |
#The following parameter can be also included in fastcgi_params file | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires max; | |
log_not_found off; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'phpmailer_init', 'setup_phpmailer_init' ); | |
function setup_phpmailer_init( $phpmailer ) { | |
$phpmailer->Host = 'HOSTNAME'; // for example, smtp.mailtrap.io | |
$phpmailer->Port = 587; // set the appropriate port: 465, 2525, etc. | |
$phpmailer->Username = 'YOURUSERNAME'; // your SMTP username | |
$phpmailer->Password = 'YOURPASSWORD'; // your SMTP password | |
$phpmailer->SMTPAuth = true; | |
$phpmailer->SMTPSecure = 'tls'; // preferable but optional | |
$phpmailer->IsSMTP(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment