我目前正在使用xampp来测试我的php代码的形式。我试图在提交时通过电子邮件将表格发送到我的电子邮件中。我已经编辑了sendmail.ini和php.ini,香港专业教育学院也尝试使用laragon,仍然收到错误。当我在xampp中检查sendmail错误页面时,我得到了20/04/21 16:28:07:(#AUTH005)太多错误的身份验证尝试。在本地服务器上运行我的PHP代码后。
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
<form action="action_page.php" method="post">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name..">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
<label for="email">Email</label>
<input type="text" id="email" name="email" placeholder="Your email..">
<label for="subject">Subject</label>
<textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
<?php
// define variables and set to empty values
$firstname = $lastname = $email = $comment = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$firstname = test_input($_POST["firstname"]);
$lastname = test_input($_POST["lastname"]);
$email = test_input($_POST["email"]);
$subject = test_input($_POST["subject"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php
echo "<h2>Your Information:</h2>";
echo $firstname;
echo "<br>";
echo $lastname;
echo "<br>";
echo $email;
echo "<br>";
echo $subject;
echo "<br>";
?>
<?php
// the message
$msg = "New contact submission";
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
// send email
mail("websiteforms.mccomasinsurance@yahoo.com","form sub.",$msg);
?>
sendmail.ini
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
error_logfile=error.log
auth_username=myemail
auth_password=
pop3_server=
pop3_username=
pop3_password=
force_sender=
force_recipient=
hostname=localhost
php.ini
; For Win32 only.
; http://php.net/smtp
;SMTP=localhost
; http://php.net/smtp-port
;smtp_port=25
...
sendmail_from = myemail
....
sendmail_path ="C:\xampp\sendmail\sendmail.exe"
答案 0 :(得分:0)
在本地进行开发时,电子邮件测试经常出现。设置sendmail服务器,尤其是在Windows上,不是一件容易的事。当您要使用外部SMTP时,它还会导致许多问题。我看到您已经配置了Google的SMTP服务器;但这绝对是一个问题,有几个原因。出于测试目的,您在本地不能拥有有效的,公认的SSL证书,而只能是PC上的一个自行生成并在本地签名的证书,这是其中之一。因此,肯定会被Internet上的每台服务器拒绝。
我的建议是,在自己的PC上进行开发时,使用小型本地服务器来测试电子邮件的发送。
我使用MailSlurper。这非常简单,一旦启动,您就可以在http://localhost:8080
上看到包含收到的电子邮件的面板。
尝试安装MailSlurper,从php.ini禁用SendMail,并使用正确的协议,smtp主机和端口设置php.ini。在我的本地配置中,我有这种电子邮件发送设置:
protocol = 'smtp';
smtp_host = 'localhost';
smtp_port = 2500;
starttls = FALSE;