2016-01-07 3 views
0

Обновление: теперь мой send.php выглядит так и, когда я нажимаю кнопку send, получает пустую страницу и ничего не посылает. У меня есть class.phpmailer.php в нужном месте.Отправить html-форму в php с smtp

<html> 
<head> 
<title>PHPMailer - SMTP basic test with authentication</title> 
</head> 
<body> 

<?php 

error_reporting(E_STRICT); 

date_default_timezone_set('America/Toronto'); 

require_once('class.phpmailer.php'); 

$mail    = new PHPMailer(); 



$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "mail.******.hu"; // SMTP server 
$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Host  = "mail.******.hu"; // sets the SMTP server 
$mail->Port  = 465;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]******.hu"; // SMTP account username 
$mail->Password = "******";  // SMTP account password 

$mail->SetFrom('[email protected]******.hu', 'First Last'); 

$mail->AddReplyTo("[email protected]******.hu","First Last"); 

$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$address = "[email protected]******.hu"; 
$mail->AddAddress($address, "[email protected]******.hu"); 

    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $phone = $_POST['phone']; 
    $call = $_POST['call']; 
    $website = $_POST['website']; 
    $priority = $_POST['priority']; 
    $type = $_POST['type']; 
    $message = $_POST['message']; 
    $address = "[email protected]******.hu"; 

    $formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message"; 
    $formcontent= eregi_replace("[\]",'',$formcontent); 
    $mail->MsgHTML($formcontent); 


if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 

?> 

</body> 
</html> 

Helo! Я хочу отправить html-форму по электронной почте с этим кодом php, но не работает ... Не знаю, почему ... Если вы знаете решение, пожалуйста, помогите мне :) Спасибо!

HTML-форма:

<div id="stylized" class="myform"> 

<form id="form1" action="send.php" method="POST"> 

    <label>Név 
     <span class="small">Kérem adja meg nevét</span> 
    </label> 
<input type="text" name="name"> 
    <label>Email 
     <span class="small">Kérem valós címet adjon meg</span> 
    </label> 
<input type="text" name="email"> 


<br /> 
<br /> 

    <label>Telefon 
     <span class="small">Visszahíváshoz adja meg telefonszámát</span> 
    </label> 
<input type="text" name="phone"> 

<br /> 
<br /> 

    <label>Elérhetőség 
     <span class="small">Kérem adja meg mikor érhetjük el telefonon</span> 
    </label> 

<select name="priority" size="1"> 
<option value="Low">Délelőtt</option> 
<option value="Normal">Délután</option> 
<option value="High">Este</option> 
<option value="Emergency">Egész nap</option> 
</select> 
<br /> 
<br /> 
<br /> 
    <label>Szolgáltatás 
     <span class="small">Mivel kapcsolatban keres minket?</span> 
    </label> 
<select name="type" size="1"> 
<option value="update">Szolgáltatás Megrendelése</option> 
<option value="change">Szolgáltatás Lemondás</option> 
<option value="addition">Információ</option> 
<option value="new">Hiba Bejelentése</option> 
</select> 
<br /> 
<br /> 
<br /> 

    <label>Tárgy 
     <span class="small">Írja le az üzenet tárgyát</span> 
    </label> 
<input type="text" name="website"> 

<br /> 
<br /> 
<br /> 

    <label>Üzenet 
     <span class="small">Írja le üzenetét</span> 
    </label> 
<textarea name="message" rows="15" cols="29"></textarea><br /> 

    <button type="submit" value="Send" style="margin-top:15px;">Küldés</button> 
<div class="spacer"></div> 

</form> 

</div> 

И мой PHP:

<?php 

    //error_reporting(E_ALL); 
    error_reporting(E_STRICT); 



    $mail    = new PHPMailer(); 


    $formcontent    = eregi_replace("[\]",'',$formcontent); 

    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->Host  = "mail.myserver.hu"; // SMTP server 
    $mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
               // 1 = errors and messages 
               // 2 = messages only 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Host  = "mail.myserver.hu"; // sets the SMTP server 
    $mail->Port  = 465;     // set the SMTP port for the GMAIL server 
    $mail->Username = "[email protected]"; // SMTP account username 
    $mail->Password = "myserverpass";  // SMTP account password 

    $mail->SetFrom('[email protected]', 'First Last'); 

    $mail->AddReplyTo("[email protected]","First Last"); 

    $mail->Subject = "test"; 

    $mail->AltBody = "test"; // optional, comment out and test 

    $mail->MsgHTML($formcontent); 

    $formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message"; 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $phone = $_POST['phone']; 
    $call = $_POST['call']; 
    $website = $_POST['website']; 
    $priority = $_POST['priority']; 
    $type = $_POST['type']; 
    $message = $_POST['message']; 
    $address = "[email protected]"; 



    if(!$mail->Send()) { 
     echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 
     echo "Message sent!"; 
    } 

    ?> 

    </body> 

</html> 

Пожалуйста, помогите мне, если вы можете! :) Thaks!

+2

Какая ошибка? – KiwiJuicer

+0

Проверьте конец кода PHP. Он имеет '' и' '. Также поместите PHP-код в файл 'send.php' и сохраните его в той же папке, где у вас есть файл HTML. Если вы столкнулись с какой-либо ошибкой, отправьте ее. –

+0

У меня ошибка сервера 500, но мой файл .htaccess в порядке. Я протестировал PHP-почерк с базовым и его работой. Но мой код не работает –

ответ

0

Вы можете добавить $mail->SMTPSecure = "ssl";

+0

Server 500 error :( –

0

Вы просто сделали одну ошибку, вы должны поставить все переменные перед их использовать, как это:

$name = $_POST['name']; 
    $email = $_POST['email']; 
    $phone = $_POST['phone']; 
    $call = $_POST['call']; 
    $website = $_POST['website']; 
    $priority = $_POST['priority']; 
    $type = $_POST['type']; 
    $message = $_POST['message']; 
    $address = "[email protected]"; 

    $formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message"; 
    $formcontent= eregi_replace("[\]",'',$formcontent); 
    $mail->MsgHTML($formcontent); 
+0

Получил тот же сервер 500 ошибка –

+0

Повторите попытку, я меняю код –

+0

server 500error :(я не знаю, почему ... –

0

Вы можете использовать почту основной функции PHP ... с этот короткий код:

Class Mailer{ 

     public static function sendMailNewUser($username,$firstname,$lastname,$password){ 

      $to = $username; 
      $from_name = "INFO MAIL"; 
      $from_mail = "[email protected]"; 
      $subject = "New User"; 

      $uid = md5(uniqid(time())); 

      // header 
      $header = "From: ".$from_name." <".$from_mail.">\r\n"; 
      $header .= "MIME-Version: 1.0\r\n"; 
      $header .= "Content-Type: text/html; charset=utf8\r\n"; 
      $message = "Welcome $firstname $lastname, "; 
      $message .= "<br><br>"; 
      $message .= "This is your account:<br> 
         <b>username: $to<br> 
         password: $password</b><br>"; 


      mail($to, $subject, $message, $header); 


     } 

} 
+0

C не используйте это, потому что мой хостинг не включает функцию почты. –

+0

Ах, извините ... с моим хостингом это мое решение – rdn87

Смежные вопросы