我對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