Skip to content

Instantly share code, notes, and snippets.

@hoasung01
Last active September 16, 2016 03:43
Show Gist options
  • Save hoasung01/d8162002d8617e5f719a49674ba39e7b to your computer and use it in GitHub Desktop.
Save hoasung01/d8162002d8617e5f719a49674ba39e7b to your computer and use it in GitHub Desktop.
mailerphp
<?php
require_once('./Mail-1.3.0/Mail.php');
echo '>>> vao diiiii >>>>';
if(isset($_POST['send'])):
echo '>>>>vao submit>>>>';
if(isset($_POST['g-recaptcha-response'])):
echo '>>>>vao check recaptcha >>>';
//your site secret key
$secret = 'xxx';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success):
echo '>>>>> captcha success>>>>>';
//contact form submission code
$first_name = !empty($_POST['first_name'])?$_POST['first_name']:'';
echo '>>> first_name >>>>>', $first_name, '';
$last_name = !empty($_POST['last_name'])?$_POST['last_name']:'';
$email = !empty($_POST['email'])?$_POST['email']:'';
$title = !empty($_POST['subject'])?$_POST['subject']:'';
$message = !empty($_POST['message'])?$_POST['message']:'';
$to = 'nguyenngochai.shipagent@gmail.com';
$subject = 'New contact form have been submitted from staging1';
$htmlContent = "
<h1>Contact request details</h1>
<p><b>First Name: </b>".$first_name."</p>
<p><b>Last Name: </b>".$last_name."</p>
<p><b>Subject: </b>".$title."</p>
<p><b>Email: </b>".$email."</p>
<p><b>Message: </b>".$message."</p>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <'.$email.'>' . "\r\n";
//send email
echo '>>>>bat dau khoi tao smtp >>>';
echo Mail::factory();
$smtp = Mail::factory('smtp', array(
'host' => 'smtp.sendgrid.net',
'port' => '587',
'auth' => true,
'username' => 'xxx',
'password' => 'xxx'
));
echo $smtp;
// @mail($to,$subject,$htmlContent,$headers);
$mail = $smtp->send($to, $headers, $htmlContent);
echo 'checking send mail >>>>';
echo 'checking to', $to, '';
echo 'checking subject', $subject, '';
echo 'checking htmlcontent', $htmlContent, '';
echo 'checking headers', $headers, '';
//echo @mail($to,$subject,$htmlContent,$headers);
echo $mail;
$succMsg = 'Your contact request have submitted successfully.';
echo '>>checking msg', $succMsg, '';
//header("Location: http://staging1.avenue28.com/contact-us/new/");
else:
$errMsg = 'Robot verification failed, please try again.';
echo 'recaptcha failed>>>>>>';
// header("Location: http://staging1.avenue28.com/contact-us/new/");
endif;
else:
$errMsg = 'Please click on the reCAPTCHA box.';
endif;
else:
$errMsg = '';
$succMsg = '';
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment