Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST['submit'])) {
- date_default_timezone_set('US/Central');
- require 'PHPMailer-5.2.26/PHPMailerAutoload.php';
- function sendemail(
- $SK_emailTo,
- $SK_emailSubject,
- $SK_emailBody
- ) {
- $mail = new PHPMailer(true);
- $mail->setFrom('myEmail@gmail.com', 'My Name');
- $mail->addReplyTo($_POST['email'], $_POST['name']);
- $mail->addAddress($SK_emailTo);
- $mail->Subject = $SK_emailSubject;
- $mail->Body = $SK_emailBody;
- $mail->isHTML(true);
- $mail->isSMTP();
- $mail->Host = 'smtp.gmail.com';
- $mail->SMTPAuth = true;
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
- $mail->Username = 'myEmail@gmail.com';
- $mail->Password = 'myPwd';
- return $mail->send();
- } //end function sendemail
- $name = $_POST['name'];
- $email = $_POST['email'];
- $message = $_POST['message'];
- try {
- sendemail(
- 'myEmail@address.com',
- 'First email subject',
- 'Form results to me...
- <br><br>'.$message
- );
- sendemail(
- $email,
- 'Second email subject',
- 'Confirmation email to person who submitted the form...
- <br><br>'.$message
- );
- echo 'Email sent!';
- } //end try
- catch (phpmailerException $e) { //catches PHPMailer errors
- echo 'There is a problem; the message did NOT send. Please go back and check that you have filled in all the required fields and there are no typos in your email address.';
- echo $e->errorMessage();
- }
- catch (Exception $e) { //catches validation errors
- echo 'There is a problem; the message did NOT send. Please either go back and try again or contact us at email@address.com';
- echo $e->getMessage();
- }
- function validateEmpty($string, $name = 'name') {
- $string = trim($string);
- if ($string == '') {
- throw new Exception(sprintf('%s is empty.', $name));
- }
- }
- } //end if submit
- ?>
Add Comment
Please, Sign In to add comment