我想讓PHPMailer工作從表單數據(顯然)發送郵件。PHPMailer發送到空白頁
問題:
當提交表單,我收到發送到一個空白頁。沒有錯誤報告。我已經按照我所能找到的圍繞此問題的許多計算器線程進行了處理,並且這些線程中沒有任何解決方案可以解決這個問題。
感謝
錯誤:
從修正所有錯誤的旁白:2016年3月26日22時10分43秒SMTP錯誤:無法連接到服務器:連接被拒絕(111)2016年3月26日22:10:43 SMTP連接()失敗。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
PHP:
<?php
$message=
'First Name: '.$_POST['first'].'<br />
Last Name: '.$_POST['last'].'<br />
Phone: '.$_POST['phone'].'<br />
Email: '.$_POST['email'].'<br />
Message: '.$_POST['message'].'
';
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tls"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 587;
// Authentication
$mail->Username = "[email protected]"; // Your full Gmail address
$mail->Password = "xxxx"; // Your Gmail password
// Compose
$mail->SetFrom($_POST['email'], $_POST['firstname'] . ' ' . $_POST['lastname']);
$mail->AddReplyTo($_POST['email'], $_POST['firstname'] . ' ' . $_POST['lastname']);
$mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress("[email protected]", "xxxx"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
}
?>
HTML:
<form class="form-inline" name="contactform" action="mailer.php" enctype="multipart/form-data" method="POST">
<div class="col-sm-6 form-group form-sty">
<label class="sr-only" for="first" required>First Name</label>
<input type="text" class="form-control-sty" name="first" placeholder="First Name">
</div>
<div class="col-sm-6 form-group form-sty">
<label class="sr-only" for="last" required>Last Name</label>
<input type="text" class="form-control-sty" name="last" placeholder="Last Name">
</div>
<div class="col-sm-6 form-group form-sty">
<label class="sr-only" for="phone" required>Phone</label>
<input type="text" class="form-control-sty" name="phone" placeholder="Phone">
</div>
<div class="col-sm-6 form-group form-sty">
<label class="sr-only" for="email" required>Email</label>
<input type="email" class="form-control-sty" name="mailfrom" placeholder="Email">
</div>
<div class="col-sm-12 form-sty">
<label class="sr-only" for="comment">Comment</label>
<textarea class="form-control-sty" name="message" id="message" rows="7" placeholder="What's on your mind?" required></textarea>
</div>
<div class="col-sm-12 form-sty form-sty-btn">
<button type="submit" value="Submit" class="btn btn-default col-sm-12">Send</button>
</div>
<p><?php if(!empty($message)) echo $message; ?></p>
</form>
你說你有一個問題,然後不說什麼問題*是*。你得到什麼錯誤/警告?如果您只是發佈格式不正確的代碼的牆,我們如何幫助您? –
請放棄請求和編輯。只需添加相關的代碼並清楚地說明問題。 – j08691
對不起,它在標題中。問題在於,PHPMailer在提交後將我發送到空白頁面。 我沒有收到任何錯誤,只是進入了空白頁面。 – dbrree