Skip to content

Instantly share code, notes, and snippets.

@csdy
Last active May 3, 2018 03:20
Show Gist options
  • Save csdy/7291d836c9b587f453683889290c35ac to your computer and use it in GitHub Desktop.
Save csdy/7291d836c9b587f453683889290c35ac to your computer and use it in GitHub Desktop.
A collection of useful PHP scripts used to test various features of your PHP installation.
<?php
// Initialize resource
$curl = curl_init();
// Set options
curl_setopt($curl, CURLOPT_URL, 'http://example.com');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// Open connection
$output = curl_exec($curl);
// Close connection
curl_close($curl);
// Display output
echo $output;
<?php
// Disable all errors
error_reporting(0);
@ini_set('display_errors', 0);
// Enable simple script errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
@ini_set('display_errors', 1);
// Enable all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
@ini_set('display_errors', 1);
// Enable all script errors
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
@ini_set('display_errors', 1);
// Enable all errors
error_reporting(E_ALL);
@ini_set('display_errors', 1);
@ini_set('display_startup_errors', 1);
<?php
phpinfo();
<?php
// Recipient
$mailTo = '[email protected]';
// Sender
$mailFrom = '[email protected]';
// Subject
$mailSubject = 'Test Message';
// Message
$mailBody = 'Contents of the message go here.';
// Headers
$mailHeaders = 'From: ' . $mailFrom . "\r\n" . 'Reply-To: ' . $mailFrom;
// Send message
if (mail($mailTo, $mailSubject, $mailBody, $mailHeaders)) {
echo 'Message was sent successfully!';
} else {
echo 'Message could not be sent.';
}
<?php
// Import PHPMailer classes
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Download PHPMailer from here:
// https://github.com/PHPMailer/PHPMailer/archive/master.zip
// Load PHPMailer files
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
// Enable debugging
$mail = new PHPMailer(true);
try {
// Debug SMTP connection
$mail->SMTPDebug = 2;
// Enable SMTP
$mail->isSMTP();
// Enable SMTP Authentication
$mail->SMTPAuth = true;
// Server hostname
$mail->Host = 'mail.example.com';
// Server username
$mail->Username = '[email protected]';
// Server password
$mail->Password = 'secret';
// Server Port
$mail->Port = 587;
// Enable encryption
$mail->SMTPSecure = 'tls';
// Sender address
$mail->setFrom('[email protected]');
// Recipient address
$mail->addAddress('[email protected]');
// Enable HTML
$mail->isHTML(true);
// Message subject
$mail->Subject = 'Test Message';
// Message body (HTML)
$mail->Body = 'This is just a test. <b>Please disregard!</b>';
// Message body (Plaintext)
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
// Send the message
$mail->send();
echo 'Message was sent successfully!';
} catch (Exception $e) {
// Display error
echo 'Message could not be sent. Mailer error: ', $mail->ErrorInfo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment