所以我有一个联系表格,当需要所有信息并且您按“发送消息”时,它会显示一条消息说“您的消息已发送”但实际上它没有发送任何内容给我希望它发送到的电子邮件。顺便说一句,xampp 中的邮件服务器。
前端:
<?php
if($message_sent):
?>
<h3>Your message has been sent</h3>
<?php
else:
?>
<div class="Form-container">
<form action="mail.php" method="POST" class="form">
<div class="form-group">
<label for="name" class="form-label">Your Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Full Name" tabindex="1" required>
</div>
<div class="form-group">
<label for="email" class="form-label">Your Email</label>
<input type="email" class="form-control <?= $invalid_class_name ?? "" ?>" id="email" name="email" placeholder="jane@doe.com" tabindex="2" required>
</div>
<div class="form-group">
<label for="subject" class="form-label">Subject</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="Hello There!" tabindex="3" required>
</div>
<div class="form-group">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" rows="5" cols="50" id="message" name="message" placeholder="Enter Message..." tabindex="4"></textarea>
</div>
<div>
<button type="submit" class="submit-btn">Send Message!</button>
</div>
</form>
</div>
<?php
endif;
?>
后端:
<?php
$message_sent = false;
if(isset($_POST['email']) && $_POST['email'] != ''){
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "petrus9572@gmail.com";
$body = "";
$body .= "From: ".$name. "\r\n";
$body .= "Email: ".$email. "\r\n";
$body .= "Message: ".$message. "\r\n";
mail($to,$subject,$body);
$message_sent = true;
}
else{
$invalid_class_name = "form-invalid";
}
}
?>
发送邮件.ini
smtp_server=smtp.mail.yahoo.com
smtp_port=465
smtp_ssl=ssl
error_logfile=error.log
auth_username=********@yahoo.com
auth_password=***********
php.ini:
SMTP=smtp.mail.yahoo.com
smtp_port=465
sendmail_from = ********@yahoo.com
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
有人可以帮忙吗
答案 0 :(得分:0)
请使用任何电子邮件服务提供商,例如 mailchamp、Sendgrid 等,并根据它设置您的 smtp。
答案 1 :(得分:0)
请使用 phpMailer 包从项目手动配置您的邮件设置。 如果您的网站未通过 ssl 认证,请使用 tls 而不是 ssl 并使用 Mailtrap 来测试邮件服务。