Skip to content

Instantly share code, notes, and snippets.

@nwittwer
Last active August 29, 2015 14:09
Show Gist options
  • Save nwittwer/08a74d30791eb095914d to your computer and use it in GitHub Desktop.
Save nwittwer/08a74d30791eb095914d to your computer and use it in GitHub Desktop.
A PHPMailer script for SMTP emails.
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
// Make sure this file is in the same folder as PHPMailerAutoload.php
require 'PHPMailerAutoload.php';
// Get the data from your form inputs
$name = strip_tags($_REQUEST['name']); // name of sender
$email = strip_tags($_REQUEST['email']); // email of sender
$message = strip_tags($_REQUEST['message']); // sender message
// Create an HTML table with your form's data
// Change the $variables to your custom ones if you used any above
$output =
'<html><body>' .
'<table rules="all" style="border-color: #666; font-size: 14px; width: 100%;" cellpadding="20">' .
"<tr><th>Contact Information</th></tr>\n" .
"<tr><td>Name:</td><td>" . $name . "</td></tr>\n" .
"<tr><td>Email:</td><td>" . $email . "</td></tr>\n" .
"<tr><td>Message:</td><td>" . $message . "</td></tr>\n" .
'</body></html>';
// Setup the mailer
$mail = new PHPMailer();
// Settings for your server (via cPanel)
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "smtp.HOSTING-COMPANY.com"; // Your SMTP server. Google your host company with SMTP to find this
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug = 0; // change to 2 to see console, 0 to hide
// Using HTML email?
$mail->IsHTML(true); // Turn on HTML
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "PASSWORD"; // SMTP password
// Email appears from who? The email itself must match the one above
$mail->From = "[email protected]";
$mail->FromName = "YOUR NAME";
// Send the email to who?
$mail->AddAddress("[email protected]"); // Send to addresses
$mail->AddAddress("[email protected]"); // Add or delete as many as you want
$mail->AddAddress("[email protected]");
$mail->addReplyTo("". $email . ""); // Reply to sender's email address
$mail->Subject = "Contact Form Submission"; // Email title
$mail->Body = $output; // Create the HTML email from the data
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment