Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_cache_limiter('nocache');
- header('Expires: ' . gmdate('r', 0));
- header('Content-type: application/json');
- require 'php-mailer/class.phpmailer.php';
- // Your email address
- $to = 'arefyev.studio@gmail.com';
- $subject = $_POST['subject'];
- if($to) {
- $name = $_POST['name'];
- $email = $_POST['email'];
- $fields = array(
- 0 => array(
- 'text' => 'Name',
- 'val' => $_POST['name']
- ),
- 1 => array(
- 'text' => 'Email address',
- 'val' => $_POST['email']
- ),
- 2 => array(
- 'text' => 'Message',
- 'val' => $_POST['message']
- )
- );
- $message = "";
- foreach($fields as $field) {
- $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
- }
- $mail = new PHPMailer;
- $mail->IsSMTP(); // Set mailer to use SMTP
- // Optional Settings
- //$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
- //$mail->SMTPAuth = true; // Enable SMTP authentication
- //$mail->Username = 'username'; // SMTP username
- //$mail->Password = 'secret'; // SMTP password
- //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
- $mail->From = $email;
- $mail->FromName = $_POST['name'];
- $mail->AddAddress($to); // Add a recipient
- $mail->AddReplyTo($email, $name);
- $mail->IsHTML(true); // Set email format to HTML
- $mail->CharSet = 'UTF-8';
- $mail->Subject = $subject;
- $mail->Body = $message;
- if(!$mail->Send()) {
- $arrResult = array ('response'=>'error');
- }
- $arrResult = array ('response'=>'success');
- echo json_encode($arrResult);
- } else {
- $arrResult = array ('response'=>'error');
- echo json_encode($arrResult);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement