2012-07-22 50 views
0
<?php 

$msg=""; 
if(isset($_POST['submit'])) 
{ 

    $from_add = "[email protected]"; 

    $to_add = "[email protected]"; //<-- I replaced this with my real gmail account 

    $subject = "Test Subject"; 
    $message = "Test Message"; 

    $headers = "From: $from_add \r\n"; 
    $headers .= "Reply-To: $from_add \r\n"; 
    $headers .= "Return-Path: $from_add\r\n"; 
    $headers .= "X-Mailer: PHP \r\n"; 


    if(mail($to_add,$subject,$message,$headers)) 
    { 
     $msg = "Mail sent OK"; 
    } 
    else 
    { 
     $msg = "Error sending email!"; 
    } 
} 
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <title>Test form to email</title> 
</head> 

<body> 
<?php echo $msg ?> 
<p> 
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'> 
<input type='submit' name='submit' value='Submit'> 
</form> 
</p> 


</body> 
</html> 

我從http://www.html-form-guide.com得到這個代碼發送電子郵件,它說,它會檢查我的服務器的配置是否正確配置爲發送電子郵件。回聲成功,但不能從遠程服務器

我試過了,我把它上傳到了我的域,當我打開它時,它顯示回顯「郵件發送正常」,但我沒有收到郵件。

請幫幫我。

+0

您是否檢查過垃圾郵件過濾器?另外,您是否將「發件人」字段更改爲有效的電子郵件地址/域名? – saluce 2012-07-22 22:53:17

+0

我不知道如何檢查垃圾郵件過濾器。請指導我。我改變了從領域。 – JetPro 2012-07-22 22:58:52

+0

只需查看垃圾郵件文件夾即可。 – saluce 2012-07-22 23:08:34

回答

2

檢查您的服務器是否設置爲發送郵件。

什麼操作系統,郵件服務器,你在用?

在Linux上,嘗試從命令行運行sendmail

echo 'this is a test'| mail -s test_email [email protected] 

其他需要檢查的是php.ini您的郵件設置是否正確,有沒有防火牆阻止外發郵件,並且該郵件是沒有得到通過垃圾郵件過濾器捕獲。

1
$from_name ="Mahendra"; 
    $from_mail = "[email protected]"; 
    $to = "[email protected]"; 
    $subject = "Mahendra's Test Mail"; 
    $mail_body = "This is email test"; 
    $message = $mail_body ; 
    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers .= "Content-type:text/html;charset=UTF-8\r\n"; 
    $headers .= "From: ".$from_name." <".$from_mail.">\r\n"; 
    ob_start(); 
    //$sendmail=mail($to,$subject,$message,$headers); 

    if($sendmail) 
    { 
     echo "Send"; 
    } 
    else 
    { 
     echo "Not Send"; 
    } 

試試上面的代碼,我敢肯定郵件使用上面的代碼發送,如果您將使用上面的代碼,並且您的郵件沒有發送。然後100%的問題出現在您的郵件服務器中。在這麼多的項目中,我使用這個和它的作品都很完美。