Php 联系人表单未向我的地址发送电子邮件

Php 联系人表单未向我的地址发送电子邮件,php,contact-form,Php,Contact Form,我的联系方式有问题,邮件没有发送到我指定的电子邮件地址。有人能告诉我我是否做错了什么吗: $emailTo = 'email@myemailwenthere.com'; $siteTitle = 'My sitename went here'; error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP //If the form is submitted if(isset($_POST['submitted']

我的联系方式有问题,邮件没有发送到我指定的电子邮件地址。有人能告诉我我是否做错了什么吗:

$emailTo = 'email@myemailwenthere.com';
$siteTitle = 'My sitename went here';

error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP

//If the form is submitted
if(isset($_POST['submitted'])) {

    // require a name from user
    if(trim($_POST['contactName']) === '') {
        $nameError =  'Forgot your name!'; 
        $hasError = true;
    } else {
        $name = trim($_POST['contactName']);
    }

    // need valid email
    if(trim($_POST['email']) === '')  {
        $emailError = 'Forgot to enter in your e-mail address.';
        $hasError = true;
    } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
        $emailError = 'You entered an invalid email address.';
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }

    // we need at least some content
    if(trim($_POST['comments']) === '') {
        $commentError = 'You forgot to enter a message!';
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $comments = stripslashes(trim($_POST['comments']));
        } else {
            $comments = trim($_POST['comments']);
        }
    }

    $subject = 'New message to ';
        $sendCopy = "";
        $body = "Name";
        $headers = 'From: ' .' <'.$email.'>';

        mail($emailTo, $subject, $body, $headers);

    // upon no failure errors let's email now!
    if(!isset($hasError)) {

        $subject = 'New message to '.$siteTitle.' from '.$name;
        $sendCopy = trim($_POST['sendCopy']);
        $body = "Name: $name \n\nEmail: $email \n\nMessage: $comments";
        $headers = 'From: ' .' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

        mail($emailTo, $subject, $body, $headers);

        //Autorespond
        $respondSubject = 'Thank you for contacting '.$siteTitle;
        $respondBody = "Your message to $siteTitle has been delivered! \n\nWe will answer back as soon as possible.";
        $respondHeaders = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $emailTo;

        mail($email, $respondSubject, $respondBody, $respondHeaders);

        // set our boolean completion value to TRUE
        $emailSent = true;
    }

尝试使用小脚本检查或发送邮件是可能的:

<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?>

我建议您尝试配置SMTP的PHPMailer,它提供了很大的灵活性


你有自己的SMTP服务器吗?或者你的网站托管?它发送到任何电子邮件地址吗?你怎么知道邮件功能正在执行?我看不到邮件被分配到任何地方。。。也许你的意思是这样做,而不是在你的有效电子邮件检查电子邮件?99.9%的时间是在php.ini邮件设置问题。可能你应该检查你的垃圾邮件箱谢谢,我已经找到了它。这是dreamhost的服务器设置问题。代码应该可以正常工作。