2016-06-29 3 views
1

Это код моей формы.Mailer с php не работает

<form method="post" action="mailer.php" id="contactfrm"> 
     <div class="col-sm-4"> 
      <div class="form-group"> 
      <label for="name">Name</label> 
      <input type="text" class="form-control" name="name" id="name" placeholder="Enter name" title="Please enter your name (at least 2 characters)"> 
      </div> 
      <div class="form-group"> 
      <label for="email">Email</label> 
      <input type="email" class="form-control" name="email" id="email" placeholder="Enter email" title="Please enter a valid email address"> 
      </div> 
     </div> 
     <div class="col-sm-4"> 
      <div class="form-group"> 
      <label for="comments">Message</label> 
      <textarea name="message" class="form-control" id="comments" cols="3" rows="5" placeholder="Enter your message…" title="Please enter your message (at least 10 characters)"></textarea> 
      </div> 
      <button name="submit" type="submit" class="btn btn-lg btn-primary" id="submit">Submit</button> 
      <div class="result"></div> 
     </div> 
     </form> 

Вот мой mailer.php

<?php 
$replyemail="my email"; 
$name = $_POST["name"]; 
$email = $_POST["email"]; 
$thesubject = "Project With Me Query"; 
$themessage = $_POST["message"]; 
$success_sent_msg='<p align="center"><strong>&nbsp;</strong></p> 
        <p align="center"><strong>Your message has been successfully sent to My Email<br> 
        </strong> and I will reply as soon as possible.</p> 
        <p align="center">A copy of your query has been sent to you.</p> 
        <p align="center">Thank you for contacting Me.</p>'; 

$replymessage = "Hi $name 

Thank you for your email. 

We will endeavour to reply to you shortly. 

Please DO NOT reply to this email. 

Below is a copy of the message you submitted: 
-------------------------------------------------- 
Subject: $thesubject 
Query: 
$themessage 
-------------------------------------------------- 

Thank you"; 

$themessage = "name: $name \nQuery: $themessage"; 
mail("$replyemail", 
    "$thesubject", 
    "$themessage", 
    "From: $email\nReply-To: $email"); 
mail("$email", 
    "Receipt: $thesubject", 
    "$replymessage", 
    "From: $replyemail\nReply-To: $replyemail"); 
echo $success_sent_msg; 

echo '<script>setTimeout(function(){location.href="index.php"} , 5000); </script>'; 
?> 

Я не могу понять, что плохого я сделал. всякий раз, когда я заполняю информацию для отображения успешного сообщения. но я не получил никакой электронной почты этой информации.

может кто-то исправить этот существующий код или предоставить мне новый код почтовой программы?

+1

Вы не проверить, является ли '' успешна почта() или нет. – Raptor

+0

Нет, я еще не @Raptor –

+0

'mail (" $ replyemail ", " $ thesubject ", " $ themessage ", " От: $ email \ nReply-To: $ email ");' I can ' что вы ожидаете, что письмо будет успешно отправлено с использованием электронной почты клиента как FROM –

ответ

1

Ваша форма

<form method="post" action="1.php" id="contactfrm"> 
     <div class="col-sm-4"> 
      <div class="form-group"> 
      <label for="name">Name</label> 
      <input type="text" class="form-control" name="name" id="name" placeholder="Enter name" title="Please enter your name (at least 2 characters)"> 
      </div> 
      <div class="form-group"> 
      <label for="email">Email</label> 
      <input type="email" class="form-control" name="email" id="email" placeholder="Enter email" title="Please enter a valid email address"> 
      </div> 
     </div> 
     <div class="col-sm-4"> 
      <div class="form-group"> 
      <label for="comments">Message</label> 
      <textarea name="message" class="form-control" id="comments" cols="3" rows="5" placeholder="Enter your message…" title="Please enter your message (at least 10 characters)"></textarea> 
      </div> 
      <button name="submit" type="submit" class="btn btn-lg btn-primary" id="submit">Submit</button> 
      <div class="result"></div> 
     </div> 
     </form> 

Ваш код PHP с SMTP

<?php 
if(isset($_POST["submit"])){ 
$replyemail="my email"; 
$name = $_POST["name"]; 
$email = $_POST["email"]; 
$thesubject = "Project With Me Query"; 
$themessage = $_POST["message"]; 
$success_sent_msg='<p align="center"><strong>&nbsp;</strong></p> 
        <p align="center"><strong>Your message has been successfully sent to My Email<br> 
        </strong> and I will reply as soon as possible.</p> 
        <p align="center">A copy of your query has been sent to you.</p> 
        <p align="center">Thank you for contacting Me.</p>'; 

$replymessage = "Hi $name 

Thank you for your email. 

We will endeavour to reply to you shortly. 

Please DO NOT reply to this email. 

Below is a copy of the message you submitted: 
-------------------------------------------------- 
Subject: $thesubject 
Query: 
$themessage 
-------------------------------------------------- 

Thank you"; 

$themessage = "name: $name \nQuery: $themessage"; 
include "PHPMailer_5.2.4/class.phpmailer.php"; 
$mail = new PHPMailer(); 

$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com"; 

$mail->Port = 465; 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "yourgmailpassword"; 
$mail->AddReplyTo($replymessage, "Reply name"); 
$mail->AddAddress($email,'ashu'); 
$mail->Subject = "SMTP Receivced"; 
$mail->Body = "<b>Succesfully SMTP Receivced</b>"; 

$mail->MsgHTML($success_sent_msg); 
$text = 'Text version of email'; 
$html = '<html><body>HTML version of email</body></html>'; 
$file = 'index.php'; 
$crlf = "\n"; 
$hdrs = array(
       'From' => '[email protected]', 
       'Subject' => 'Test mime message' 
      ); 
if($mail->send($hdrs)) 
{ 
echo "<script> alert('Successfully Mailed');window.location = '';</script>"; 
} 
else{ 
echo "Mailed Error: " . $mail->ErrorInfo; 
} 
} 

//echo '<script>setTimeout(function(){location.href="pra-2.php"} , 5000); </script>'; 
?> 

enter image description here

+0

ashu есть файл отсутствует error Предупреждение: include (PHPMailer_5.2.4/class.phpmailer.php): не удалось открыть поток: нет такого файла или каталога в/home/minif8rq/public_html/mydomain.in/mailer.php on line 32 –

+0

** class.phpmailer.php **, пожалуйста, дайте мне ссылку на этот файл –

+0

** Неустранимая ошибка: Class 'SMTP' не найден в /home/minif8rq/public_html/mydomian.in /class.phpmailer.php в строке 1466 ** –