2011-06-23 116 views
2

任何人都可以看到這是否有什麼問題嗎?我沒有得到任何錯誤,但從來沒有收到郵件。簡單的PHP郵件不發送電子郵件

<?php 
if(isset($_POST['email'])) { 

    // EDIT THE 2 LINES BELOW AS REQUIRED 
    $email_to = "[email protected]"; 
    $email_subject = "Email sent through crankapps website"; 

    function died($error) { 
     // your error code can go here 
     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
     echo "These errors appear below.<br /><br />"; 
     echo $error."<br /><br />"; 
     echo "Please go back and fix these errors.<br /><br />"; 
     die(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['message'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
    } 

    $name = $_POST['name']; // required 
    $email = $_POST['email']; // required 
    $message = $_POST['message']; // required 

    $error_message = ""; 
    $email_message = "Form details below.\n\n"; 

    $email_message .= "Name: ".clean_string($name)."\n"; 
    $email_message .= "Email: ".clean_string($email)."\n"; 
    $email_message .= "Message: ".clean_string($message)."\n"; 


// create email headers 
$headers = "From: ". $name . " <" . $email . ">\n."; 
mail($email_to, $email_subject, $email_message, $headers); 
?> 

回答

3

首先,測試只用一條線:

<?php 
    mail('[email protected]', 'test email', 'this is a test'); 
?> 

有機會,這是不行的。

找出你的smtp設置,看看你的php.ini中的smtp設置是否與它們匹配。

看看phpmailer,它可以讓你使用更多的SMTP設置,如ssl等

+1

好建議謝謝。原來我的郵箱已滿! :) –