Skip to content

Instantly share code, notes, and snippets.

@bhandarisaurav
Last active August 8, 2018 08:50
Show Gist options
  • Save bhandarisaurav/487c4d1d927266c104bae09e4d4dad10 to your computer and use it in GitHub Desktop.
Save bhandarisaurav/487c4d1d927266c104bae09e4d4dad10 to your computer and use it in GitHub Desktop.
Simple script made with PHP mailer that helps to send emails for the project. Simply put your gmail username and password in the respective place and write the sending address and you are ready to go. Download the required files here : https://goo.gl/W9WbW5
<?php require 'class/class.phpmailer.php';
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$bodyContent = "hello ".$name;
$mail = new PHPMailer;
$mail->CharSet = "UTF-8";
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
$mail->Host = 'smtp.gmail.com'; //Sets the SMTP hosts of your Email hosting, this for gmail
$mail->Port = '587'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = '[email protected]'; //Sets SMTP username
$mail->Password = 'password'; //Sets SMTP password
$mail->SMTPSecure = 'tls'; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = "[email protected]"; //Sets the From email address for the message
$mail->FromName = 'From Name'; //Sets the From name of the message
$mail->AddAddress("[email protected]", "Name"); //Adds a "To" address
$mail->AddCC("[email protected] ", "CC Name"); //Adds a "Cc" address
$mail->AddCC("[email protected]", "CC1 Name"); //Adds a "Cc" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
$mail->Hostname = 'localhost.localdomain'; //to send unlimited emails from localhost
$mail->IsHTML(true); //Sets message type to HTML if you want to send message with html tags
$mail->Subject = "Subject"; //Sets the Subject of the message
$mail->Body = $bodyContent; //An HTML or plain text message body
if ($mail->Send()) //Send an Email. Return true on success or false on error
{
echo "<SCRIPT type='text/javascript'>
alert('Contact Form Successfully Submitted!');
window.location.replace('thanks.php');</SCRIPT>";
} else {
echo "<SCRIPT type='text/javascript'>
alert('Your form could not be sent. Please try again later.');
window.location.replace('thanks.php');</SCRIPT>";
// header("Refresh:0");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment