简单的php邮件不发送电子邮件

时间:2011-06-23 23:15:13

标签: php email

有人能看出这有什么问题吗?我没有错,但从未收到电子邮件。

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

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "munged@example.com";
    $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); 
?>

1 个答案:

答案 0 :(得分:3)

首先,只用一行进行测试:

<?php
    mail('munged@example.com', 'test email', 'this is a test');
?>

这可能不起作用。

找出你的smtp设置,看看php.ini中的smtp设置是否与它们匹配。

看一下phpmailer,它允许你使用更多的smtp设置,比如ssl等。