为什么我的联系表格不能使用PHPMailer工作?

时间:2016-07-04 14:41:50

标签: php

我创建了一个联系表单,将信息发送到我的电子邮箱,每当我提交表单时,我都会被重定向到我的php文件(mywebsite.com/contact.php)并显示内部服务器错误(500种) 。我做错了什么?可能是因为我的html和php代码在不同的文件中?我也包括了我的联系表格,以防它是相关的。

<?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 = 'aroncea@yahoo.com';                 // 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('aroncea@yahoo.com');     // 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> aroncea@yahoo.com</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>

2 个答案:

答案 0 :(得分:0)

您在PHP文件中缺少}。 (您在{ - 语句后打开if但从未关闭它。)

有500个错误,通常有助于检查服务器错误日志。

答案 1 :(得分: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 = 'aroncea@yahoo.com';                 // 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('aroncea@yahoo.com');     // Add a recipient

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

我希望它会有所帮助

相关问题