Created
October 13, 2015 11:19
-
-
Save surjithctly/bbc21d56e03990fb3ed9 to your computer and use it in GitHub Desktop.
Simple PHPMailer() Contact Form
This file contains hidden or 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 | |
require_once "phpmailer/class.phpmailer.php"; | |
//PHPMailer Object | |
$mail = new PHPMailer; | |
//From email address and name | |
$mail->From = "[email protected]"; | |
$mail->FromName = "Full Name"; | |
//To address and name | |
$mail->addAddress("[email protected]", "Recepient Name"); | |
$mail->addAddress("[email protected]"); //Recipient name is optional | |
//Address to which recipient will reply | |
$mail->addReplyTo("[email protected]", "Reply"); | |
//CC and BCC | |
$mail->addCC("[email protected]"); | |
$mail->addBCC("[email protected]"); | |
//Send HTML or Plain Text email | |
$mail->isHTML(true); | |
$mail->Subject = "Subject Text"; | |
$mail->Body = "<i>Mail body in HTML</i>"; | |
$mail->AltBody = "This is the plain text version of the email content"; | |
if(!$mail->send()) | |
{ | |
echo "Mailer Error: " . $mail->ErrorInfo; | |
} | |
else | |
{ | |
echo "Message has been sent successfully"; | |
} |
This file contains hidden or 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 | |
require_once "phpmailer/class.phpmailer.php"; | |
//class.smtp.php is also needed when sending via SMTP | |
$mail = new PHPMailer; | |
//Enable SMTP debugging. | |
$mail->SMTPDebug = 3; | |
//Set PHPMailer to use SMTP. | |
$mail->isSMTP(); | |
//Set SMTP host name | |
$mail->Host = "smtp.gmail.com"; | |
//Set this to true if SMTP host requires authentication to send email | |
$mail->SMTPAuth = true; | |
//Provide username and password | |
$mail->Username = "[email protected]"; | |
$mail->Password = "super_secret_password"; | |
//If SMTP requires TLS encryption then set it | |
$mail->SMTPSecure = "tls"; | |
//Set TCP port to connect to | |
$mail->Port = 587; | |
$mail->From = "[email protected]"; | |
$mail->FromName = "Full Name"; | |
$mail->addAddress("[email protected]", "Recepient Name"); | |
$mail->isHTML(true); | |
$mail->Subject = "Subject Text"; | |
$mail->Body = "<i>Mail body in HTML</i>"; | |
$mail->AltBody = "This is the plain text version of the email content"; | |
if(!$mail->send()) | |
{ | |
echo "Mailer Error: " . $mail->ErrorInfo; | |
} | |
else | |
{ | |
echo "Message has been sent successfully"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment