我整理了一个运行nginx,PHP和MSMTP的Docker映像。 我可以交互方式从容器中发送电子邮件,但是当我尝试从PHP脚本发送电子邮件时,它会失败。 我正在努力弄清楚为什么我无法正确地将日志记录到正确的管道上,但这是一个单独的问题。 我真的只需要发送电子邮件,这样我就可以关闭这个小型迷你项目。 任何帮助都得到了极大的赞赏。 另外,PHP工作正常,没有错误的说法。 dockerfile

问题描述 投票:0回答:0

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>

send_email.php
<?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个以上的参数之后非常井井有条。它应该接受更多(例如电子邮件标题),但似乎不起作用。
    

php docker nginx dockerfile msmtp
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.