PHP邮件功能不发送,代码有问题

时间:2013-11-25 13:28:59

标签: php email

我正在使用linux系统

我在我的网站上尝试过测试邮件php脚本,它可以使用该脚本。但出于某种原因,不是我的。有没有人看错了什么?

        $title = "Confirmation Required";   
        $msg = "An email has been sent to you with a confirmation link and your password.  Once clicking the link you will be asked to change your password and you will be ready to start earning!.<br><center><h2>The email was sent to <strong>$email</strong>.</h2></center><center>Go Check Your Email And Confirm Your Account</center><br>";

    $to = $email;
    $subject = "Confirm New Account";
    $message = "<h2>Welcome</h2> <h4><a href='$siteUrl/confirm.php?key=$userId'> Click Here To Confirm Account </a></h4> Your login information.<br>Login: <strong>$email</strong> <br> Password: <strong>$userId</strong>";
$headers .= "X-Mailer: PHP \r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Member <$email>' . "\r\n";
$headers .= 'From:  <' . $adminEmail. '>' . "\r\n";
    mail($to,$subject,$message,$headers);


    } // all good  

    echo "Mail sent OK";

    } 

这是我的php.ini文件

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t;
sendmail_from = Contact@mysite.com

2 个答案:

答案 0 :(得分:1)

尝试更改此行:

$headers .= 'To: Member <$email>' . "\r\n";

对此:

$headers .= 'To: Member <' . $email . '>' . "\r\n";

答案 1 :(得分:0)

可能邮件服务器坏了。我以前遇到过这个问题,它正在工作然后突然停止工作。请检查:PHP Mail just suddenly stop working

或者,可能是您的邮件配置设置错误。