我对 php 还很陌生,我最近尝试使用邮件功能,但它不起作用。这是我的代码:
<?php
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$topic = $_POST['topic'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with your own)
$to = 'tishsny@gmail.com';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
// Send the mail using PHPs mail() function
if( mail($to, $subject, $message, $headers) ) header("Location:../forms/success.html");
else header( "Location:../forms/failure.html" );
?>
我将 sendmail 的路径添加到 php.ini 文件中,但它仍然无法正常工作。mail 函数总是返回 true,但我没有收到任何邮件。mail.log 显示了一堆超时。这是一些输出:
postfix/qmgr[3523]: BB800B124A: from=<_www@Leticias-MacBook-Pro.local>, size=382, nrcpt=1 (queue active)
postfix/qmgr[3523]: CB34EB0E9F: from=<_www@Leticias-MacBook-Pro.local>, size=405, nrcpt=1 (queue active)
postfix/qmgr[3523]: D6C18B0D7B: from=<_www@Leticias-MacBook-Pro.local>, size=394, nrcpt=1 (queue active)
postfix/smtp[3527]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c01::1b]:25: No route to host
postfix/smtp[3533]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c01::1b]:25: No route to host
postfix/pickup[3522]: 8A9EEB1823: uid=70 from=<_www>
postfix/cleanup[3524]: 8A9EEB1823: message-id=<20130321193156.8A9EEB1823@Leticias-MacBook-Pro.local>
postfix/qmgr[3523]: 8A9EEB1823: from=<_www@Leticias-MacBook-Pro.local>, size=392, nrcpt=1 (queue active)
postfix/smtp[3526]: connect to mx3.hotmail.com[65.55.37.72]:25: Operation timed out
postfix/smtp[3531]: connect to gmail-smtp-in.l.google.com[74.125.141.27]:25: Operation timed out
postfix/smtp[3531]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c01::1b]:25: No route to host
postfix/smtp[3531]: connect to alt1.gmail-smtp-in.l.google.com[2607:f8b0:400e:c02::1b]:25: No route to host