2016-07-04 142 views
-1

我做了一個接觸的形式將信息發送給我的電子郵件,每當我提交表單,我重定向到我的PHP文件(mywebsite.com/contact.php)和我所示的內部服務器錯誤(500種)。我做錯了什麼?難道是因爲我有我的HTML和PHP代碼在不同的文件?我也包括我的聯繫表格以防萬一它是相關的。爲什麼我的聯繫表單使用PHPMailer不工作?

<?php 
 

 
if(isset($_POST['submit'])) 
 
{ 
 

 
$message= 
 
'Full Name: '.$_POST['name'].'<br/> 
 
Comments: '.$_POST['comments'].'<br/> 
 
Email:  '.$_POST['email'].' 
 
'; 
 

 
require 'phpmailer/PHPMailerAutoload.php'; 
 

 
$mail = new PHPMailer; 
 

 
//$mail->SMTPDebug = 3;        // Enable verbose debug output 
 

 
$mail->isSMTP();          // Set mailer to use SMTP 
 
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup SMTP servers 
 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
 
$mail->Username = '[email protected]';     // SMTP username 
 
$mail->Password = 'letmejusteditthisout';       // SMTP password 
 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
 
$mail->Port = 465;         // TCP port to connect to 
 

 
$mail->setFrom($_POST['email'], $_POST['name']); 
 
$mail->addReplyTo($_POST['email'], $_POST['name']); 
 

 
$mail->addAddress('[email protected]');  // Add a recipient 
 
$result = $mail->Send(); 
 
$message = $result ? 'Successfully sent!' : 'Sending Failed!'; 
 
unset($mail); 
 

 
$mail->Subject = "New Form Submission"; 
 
$mail->MsgHTML($message); 
 

 

 
?>

<!-- Container (Contact Section) --> 
 
<form action="newcontact.php" method="POST" name='contactform' id='contactform' enctype="text/plain"> 
 
<div id="contact" class="container-fluid bg-grey"> 
 
    <h2 class="text-center">CONTACT</h2> 
 
    <div class="row"> 
 
    <div class="col-sm-5"> 
 
     <p>Contact us and we'll get back to you within 24 hours. </p> 
 
     <p><span class="glyphicon glyphicon-map-marker"></span> Burlington, ON</p> 
 
     <p><span class="glyphicon glyphicon-phone"></span> 289-230-4510</p> 
 
     <p><span class="glyphicon glyphicon-envelope"></span> [email protected]</p> 
 
    </div> 
 
    <div class="col-sm-7 slideanim"> 
 
     <div class="row"> 
 
     <div class="col-sm-6 form-group"> 
 
      <input class="form-control" id="name" name="name" placeholder="Name" type="text" required> 
 
     </div> 
 
     <div class="col-sm-6 form-group"> 
 
      <input class="form-control" id="email" name="email" placeholder="Email" type="email" required> 
 
     </div> 
 
     </div> 
 
     <textarea class="form-control" id="comments" name="comments" placeholder="Comment (not required)" rows="3"></textarea><br> 
 
     <div class="row"> 
 
     <div class="col-sm-12 form-group"> 
 
      <input type="submit" name="submit" value="Submit" /> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div>

+1

是什麼在你的web服務器錯誤日誌?它看起來不像你關閉你的'if'語句。 –

回答

0

你缺少你的PHP-文件一}。 (在if-之後打開{,但從不關閉它。)

有500個錯誤,它通常有助於檢查服務器的錯誤日誌。

0

$mail->Send();和關閉}之前分配您的信息和主題。 試試這個代碼。

if(isset($_POST['submit'])) 
{ 

$message= 
'Full Name: '.$_POST['name'].'<br/> 
Comments: '.$_POST['comments'].'<br/> 
Email:  '.$_POST['email'].' 
'; 

require 'phpmailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'letmejusteditthisout';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 465;         // TCP port to connect to 

$mail->setFrom($_POST['email'], $_POST['name']); 
$mail->addReplyTo($_POST['email'], $_POST['name']); 

$mail->addAddress('[email protected]');  // Add a recipient 

$mail->Subject = "New Form Submission"; 
$mail->MsgHTML($message); 
$result = $mail->Send(); 
$message = $result ? 'Successfully sent!' : 'Sending Failed!'; 
unset($mail); 
} 

我希望這將是有益的

+0

謝謝您的評論。我做了你所說的,現在我的表單只是指向mywebsite.com/newcontact.php(這就是它的URL),這是一個完全空白的頁面,甚至沒有顯示「成功發送」或「發送失敗」 。有沒有一個網站可以去檢查PHP代碼是否正確?我可以在哪裏進行一些故障排除? – Feinmann

相關問題