mmtp.conf
# Set default values for all following accounts.
defaults
logfile ~/msmtp.log
# Gmail
account gmail
host smtp.gmail.com
port 465
tls_starttls off
from [email protected]
user username
password plain-text-password
# Office
account office
host smtp.office365.com
port 587
auth on
tls on
tls_starttls on
tls_certcheck on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
from [email protected]
user [email protected]
password password
# Set a default account
account default: office
Contact.html
<!-- Contact Form -->
<form class="row g-3" action="send_email.php" method="POST">
<div class="col-md-6">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="col-md-6">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="col-12">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
</div>
<div class="col-12 text-center">
<button type="submit" class="btn btn-primary">Send Message</button>
</div>
</form>
<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get form data
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$message = htmlspecialchars($_POST['message']);
// Set the recipient email address
$to = "[email protected]"; // Replace with your email address
// Set the email subject
$subject = "New Contact Form Submission from $name";
// Build the email content
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Set the email headers
$headers = "From: $name <$email>\r\n";
$headers .= "Reply-To: $email\r\n";
// Send the email
if (mail($to, $subject, $email_content, $headers)) {
// Email sent successfully
echo "<p>Thank you for contacting us, $name! We will get back to you soon.</p>";
} else {
// Email failed to send
echo "<p>Oops! Something went wrong. Please try again later.</p>";
}
} else {
// If the form is not submitted, redirect to the contact page
header("Location: contacts.html");
exit();
}
?>
我很清楚日志可能会有所帮助,但是说实话我整天都在试图从我的形象中获得适当的日志,但我一直在打破任何东西。
我弄清楚了。 邮件函数在传递了3个以上的参数之后非常井井有条。它应该接受更多(例如电子邮件标题),但似乎不起作用。