Надеюсь, кто-то может помочь - я пытался запустить это около недели.Отправка формы с помощью PHP Mailer
У меня была проблема с моей формой, так как некоторые серверы блокировали электронную почту, потому что электронное письмо в «из» было другим. Мне сказали использовать PHP Mailer. Я совершенно новичок в этом, поэтому я пытаюсь интегрировать его в свою форму и просто получаю пустую страницу при отправке. Может ли кто-нибудь сказать мне, что у меня не так?
<?php
$servername = "***";
$username = "***";
$password = "***";
$dbname = "***";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO guestquestionnaire (date_submitted, choice, expectations, res, res_information, res_staff, further_comments1)
VALUES (:date_submitted, :choice, :expectations, :res, :res_information, :res_staff, :further_comments1)");
$stmt->bindParam(':date_submitted', $date, PDO::PARAM_STR);
$stmt->bindParam(':choice', $choice);
$stmt->bindParam(':expectations', $expectations);
$stmt->bindParam(':res', $res);
$stmt->bindParam(':res_information', $res_information);
$stmt->bindParam(':res_staff', $res_staff);
$stmt->bindParam(':further_comments1', $further_comments1);
// insert a row
$date = date('Y-m-d H:i:s');
$choice = $_POST['choice'];
$expectations = $_POST['expectations'];
$res = $_POST['res'];
$res_information = $_POST['res_information'];
$res_staff = $_POST['res_staff'];
$further_comments1 = $_POST['further_comments1'];
$stmt->execute();
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
<?php
composer require phpmailer/phpmailer
require_once "vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "[email protected]";
$mail->FromName = "Host Person";
//To address and name
$mail->addAddress("[email protected]", "User");
$mail->addAddress("[email protected]"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("[email protected]", "Reply");
//CC and BCC
$mail->addCC("[email protected]");
$mail->addBCC("[email protected]");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Guest Questionnaire Received";
// Build message.
$img="<img src='http://www.myurl.com/guestquestionnaire/images/star".$_POST['res'].".jpg'>";
$img2="<img src='http://www.myurl.com/guestquestionnaire/images/star".$_POST['res_information'].".jpg'>";
$img3="<img src='http://www.myurl.com/guestquestionnaire/images/star".$_POST['res_staff'].".jpg'>";
$message = '<html><body>';
$message .= "<strong>Guest Questionnaire </strong>";
$message .= "<strong>Received: </strong>";
$message .= "<P>";
$message .= '<table rules="all" style="border: 1px solid #999;" cellpadding="7" width="100%" >';
$message .= "<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'><td colspan='3'>Prior to Arrival</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>What made you choose us for your recent trip? </td><td width='40%' colspan='2'>" . strip_tags($_POST['choice']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Did we meet your expectations as advertised? If no, please state why: </td><td width='40%' colspan='2'>" . strip_tags($_POST['expectations']) . "</td></tr>";
$message .= "<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'><td colspan='3'>Making your Reservation</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Ease of making your reservation: </td><td width='40%'>$img</td><td width='5%'>" . strip_tags($_POST['res']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Hotel information offered: </td><td width='40%'>$img2</td><td width='5%'>" . strip_tags($_POST['res_information']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td>Warmth and friendliness of staff: </td><td width='40%'>$img3</td><td width='5%'>" . strip_tags($_POST['res_staff']) . "</td></tr>";
$message .= "<tr style='font-size: 8pt;'><td colspan='3'>Further Comments: </BR></BR>" . strip_tags($_POST['further_comments1']) . "</td></tr>";
$message .= "</table>";
$message .= "<BR>";
$message .= "</table>";
$message .= "</body></html>";
$mail->Body = "<i>".$message."</i>";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="surveystyle.css" media="all" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery.inputfocus-0.9.min.js"></script>
<script type="text/javascript" src="/jquery.main.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
</head>
<body>
<div id="container">
<div class="logo-header"><img src="images/logo.jpg" alt="" width="205" height="119" /></div>
<div class="question-start"><h1>Thank You!</h1><p>Your evaluation <b>will</b> make a difference.</p></div>
<div id="progress_bar">
<div id="progress_end"></div>
<div id="progress_text">100% Complete</div>
</div>
</div>
</div>
</body>
UPDATE: error_log привез:
[Wed Aug 05 12:57:50 2015] [error] [client 173.58.203.164] PHP Warning: require_once(vendor/autoload.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /var/www/vhosts/myurl.com/httpdocs/guestquestionnaire/surveysubmit.php on line 113, referer: http://www.myurl.com/guestquestionnaire/
[Wed Aug 05 12:57:50 2015] [error] [client 173.58.203.164] PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'vendor/autoload.php' (include_path='.:') in /var/www/vhosts/myurl.com/httpdocs/guestquestionnaire/surveysubmit.php on line 113, referer: http://www.myurl.com/guestquestionnaire/
access_log привез:
404 7682 "http://www.myurl.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
Спасибо, я пробовал это, но, к сожалению, все еще получаю пустую страницу. Я обновил свой код выше incase Я вас неправильно понял – IVCatalina
Сделайте ssh-login, сделайте «cd/вар/WWW/виртуальных доменов/myurl.com/httpdocs/guestquestionnaire/", а затем« для компоновщика требуется phpmailer/phpmailer »для установки phpmailer. – hellcode
В качестве альтернативы (или когда у вас нет установленного композитора) смотрите: [GitHub: альтернативная установка] (https: // github. com/PHPMailer/PHPMailer # installation - loading) – hellcode