【发布时间】:2018-03-21 06:43:12
【问题描述】:
我正在 jquery 中进行表单验证并使用 wamp 服务器。但是我遇到了这两个错误
Fatal error: Uncaught Error: Call to undefined method PHPMailer:: SetForm()
和Error: Call to undefined method PHPMailer::SetForm() 我还添加了PHPMailerAutoload.php。甚至在php.ini 和Apache mail function 中设置了所有本地主机设置,但仍然会引发错误。
<?php
isset($_POST['name'],$_POST['email'],$_POST['phone'],$_POST['select'],$_POST['time'],$_POST['message']);
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail -> IsSmtp();
$mail -> SMTPDebug = 1;
$mail -> SMTPAuth = true;
$mail -> SMTPSecure = 'ssl';
$mail -> Host = 'smtp.gmail.com';
$mail -> Port = 465;
$mail -> IsHTML(true);
$mail -> Username = "your@gmail.com";
$mail -> Password = "123";
$mail -> SetForm("your@gmail.com");
$mail -> name = $name;
$mail -> body = $message;
$mail -> AddAddress = ($email);
if (!$mail -> Send()) {
echo "mail not send";
}
else {
echo "Your mail successfully sent....";
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="contact" method="post" action="form.php">
<div>
<label for="contact_name">Name:</label>
<input type="text" id="contact_name" name="name"></input>
<span class="error">This field is required</span>
</div>
<div>
<label for="contact_email">Email:</label>
<input type="email" id="contact_email" name="email"></input>
<span class="error">A valid email address is required</span>
</div>
<div>
<label for="contact_phone">Phone:</label>
<input type="number" id="contact_phone" name="phone"></input>
<span class="error">A valid Phone number is required</span>
</div>
<div>
<label for="contact_select">Number of People</label>
<select id="contact_select" name="select">
<option value="">select number of people</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<span class="error">Select Number of Members</span>
</div>
<div>
<label for="contact_time">Time</label>
<select id="contact_time" name="time">
<option value="">select Time</option>
<option value="00:00">00:00</option>
<option value="00:15">00:15</option>
</select>
<span class="error">Select Time option</span>
</div>
<div>
<label for="contact_message">Message:</label>
<textarea id="contact_message" name="message"></textarea>
<span class="error">This field is required</span>
</div>
<div id="contact_submit">
<input type="submit"></input>
</div>
</form>
【问题讨论】:
-
方法名是
setFrom,你这个英雄……与forms无关。
标签: javascript php jquery forms validation