Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'PHPMailer_5.2.4/class.phpmailer.php';
- require_once 'PHPMailer_5.2.4/class.smtp.php';
- if ($_POST) {
- $name = htmlspecialchars($_POST["name"]);
- $email = htmlspecialchars($_POST["email"]);
- $subject = htmlspecialchars($_POST["subject"]);
- $message = htmlspecialchars($_POST["message"]);
- $json = array();
- if (!$name or !$email or !$subject or !$message) {
- $json['error'] = 'Вы зaпoлнили нe всe пoля! oбмaнуть рeшили? =)';
- echo json_encode($json);
- die();
- }
- if (!preg_match("|^[-0-9a-z_\.]+@[-0-9a-z_^\.]+\.[a-z]{2,6}$|i", $email)) {
- $json['error'] = 'Нe вeрный фoрмaт email! >_<'; // пишeм oшибку в мaссив
- echo json_encode($json);
- die();
- }
- function mime_header_encode($str, $data_charset, $send_charset)
- {
- if ($data_charset != $send_charset)
- $str = iconv($data_charset, $send_charset . '//IGNORE', $str);
- return ('=?' . $send_charset . '?B?' . base64_encode($str) . '?=');
- }
- $mail = new PHPMailer(true);
- $mail->IsSMTP();
- $mail->Host = "smtp.gmail.com";
- $mail->SMTPAuth = true;
- $mail->SMTPSecure = 'ssl';
- $mail->Port = 465;
- $mail->CharSet = 'UTF-8';
- $body = $_POST['message'];
- $mail->Username = "newj**@gmail.com";
- $mail->Password = "pass";
- $mail->SetFrom('smy**@gmail.com', 'N B');
- $mail->Subject = $_POST['subject'];
- $mail->msgHTML($body);
- $mail->addAddress('newj**@gmail.com', 'N B');
- if ($mail->Send()) {
- echo "Message sent";
- } else {
- echo "ERROR: " . $mail->ErrorInfo;
- }
- echo json_encode($mail);
- $json['error'] = 0;
- echo json_encode($json);
- } else {
- echo 'Массив не был передан!';
- }
Add Comment
Please, Sign In to add comment