Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "PHPMailer/PHPMailerAutoload.php";
- $data = array();
- $data['error'] = 1;
- $data['msg'] = '';
- if(isset($_POST)){
- if(!empty($_POST)){
- $name = '';
- if(isset($_POST['name'])){
- $name = $_POST['name'];
- }
- $email = '';
- if(isset($_POST['email'])){
- $email = $_POST['email'];
- }
- $subject = '';
- if(isset($_POST['subject'])){
- $subject = $_POST['subject'];
- }
- $message = '';
- if(isset($_POST['message'])){
- $message = $_POST['message'];
- }
- $mailsubject = variable_get('site_name').' - '.'Contact Me';
- $emailTo = variable_get('contact_mail');
- $tpl = file_get_contents(drupal_get_path('module', 'elsayed').'/emails/contactus.html');
- $html_message = str_replace(array('{{mailsubject}}', '{{name}}', '{{email}}', '{{subject}}', '{{message}}'),
- array($mailsubject, $name, $email, $subject, $message), $tpl);
- if($emailTo != ''){
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->SMTPAuth = true;
- $mail->CharSet = "UTF-8";
- //$mail->SMTPSecure = 'tls';
- $mail->Host = getenv('MAIL_HOST');
- $mail->Port = getenv('MAIL_PORT');
- $mail->Username = getenv('MAIL_USERNAME');
- $mail->Password = getenv('MAIL_PASSWORD');
- $mail->From = $email;
- $mail->FromName = $name;
- $mail->addAddress($emailTo, variable_get('site_name'));
- $mail->isHTML(true);
- $mail->Subject = $mailsubject;
- $mail->Body = $html_message;
- $mail->AltBody = "This is the plain text version of the email content";
- if ($mail->send()) {
- //$data['msg'] = __('Thank you for your message. We will get back to you the soonest.');
- $data['error'] = 0;
- }else{
- //$data['msg'] = __('There was a problem sending the Email. Please try again.');
- $data['error'] = 1;
- }
- }else{
- //$data['msg'] = __('There was a problem sending the Email. Please try again.');
- $data['error'] = 1;
- }
- }
- }
- echo json_decode($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement