2010-05-03 154 views
-1
<?php 
$sendto = "[email protected]"; 
$subject = "email confirmation"; // Subject 
$message = "the body of the email - this email is to confirm etc..."; 
# send the email 
mail($sendto, $subject, $message); 
?> 

這是我編寫的用於在localhost上測試郵件功能的代碼。 我已經多次在瀏覽器中運行該腳本,但仍然在我的郵箱中收到任何電子郵件。php郵件功能

我是否需要其他配置?

thx提前!

+0

你確定它沒有在您的垃圾郵件文件夾結束了? – 2010-05-03 09:29:30

+0

您需要在執行腳本的服務器上運行郵件服務器 – knittl 2010-05-03 09:29:53

+0

如果您正在運行Windows,則只需要郵件服務器。是localhost的Windows? – Reece45 2010-05-03 14:33:05

回答

0

基本上很難發送郵件從本地主機到任何郵件提供商。 他們對傳入的郵件有很大的限制,而簡單的郵件()將不起作用。

您需要使用SMTP服務器。 和定義PHP配置

smtp = localhost #(here should be your smtp server) 
smtp_port = 25 

該服務器,如果你沒有一個SMTP服務器,試圖通過所有的頭象PHP例子:

$to  = '[email protected]'; 
$subject = 'the subject'; 
$message = 'hello'; 
$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

mail($to, $subject, $message, $headers);

http://www.php.net/manual/en/function.mail.php

0

您需要確保您的PHP安裝設置爲使用正常工作的SMTP服務器。您可能會在answers to this question中找到您要查找的內容。如果不這樣做,您可能需要在您的實時Web服務器上測試您的腳本。

-1

如果你是與localhost合作,我希望它永遠不會工作。它只能在配置郵件的服務器上工作。請嘗試一下。

0
<?php 
    $name = $_POST['name']; 
    $visitor_email = $_POST['email']; 
    $message = $_POST['message']; 
?> 
<?php 
    $email_from = '[email protected]'; 

    $email_subject = "New Form submission"; 

    $email_body = "You have received a new message from the user $name.\n". 
         "Here is the message:\n $message" 
?> 
<?php 

$to = "[email protected]"; 

$headers = "From: $email_from \r\n"; 

$headers .= "Reply-To: $visitor_email \r\n"; 

mail($to,$email_subject,$email_body,$headers); 

?> 
<?php 
$to = "[email protected], [email protected],[email protected] 
name.com"; 

    mail($to,$email_subject,$email_body,$headers); 
    ?> 
<?php 
$to = "[email protected], [email protected],[email protected] 
name.com"; 

    $headers = "From: $email_from \r\n"; 

    $headers .= "Reply-To: $visitor_email \r\n"; 

    $headers .= "Cc: [email protected] \r\n"; 

    $headers .= "Bcc: [email protected] \r\n"; 

    mail($to,$email_subject,$email_body,$headers); 
    ?> 

嘗試這個Guys..This是發送郵件