我对PHP相当陌生,最近我尝试使用邮件功能,但它不起作用。这里是我的代码:使用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 = '[email protected]';
$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文件,但它仍然不起作用。邮件功能总是返回true,但我没有收到任何邮件。 mail.log显示了一堆超时。这里有一些输出:
postfix/qmgr[3523]: BB800B124A: from=<[email protected]>, size=382, nrcpt=1 (queue active)
postfix/qmgr[3523]: CB34EB0E9F: from=<[email protected]>, size=405, nrcpt=1 (queue active)
postfix/qmgr[3523]: D6C18B0D7B: from=<[email protected]>, 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=<[email protected]>
postfix/qmgr[3523]: 8A9EEB1823: from=<[email protected]>, 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
验证出站邮件端口(端口25)是否在防火墙中未被阻止。 – 2013-03-21 19:39:12
检查您正在尝试使用本地Web服务器的php.ini – Fiarr 2013-03-21 19:39:32
中的smtp设置? – Nikitas 2013-03-21 19:46:18