ajax电子邮件功能解析错误

时间:2014-03-16 01:59:16

标签: php ajax email

在我的php文件中,我一直在第5行得到一个解析错误,这是保存来自电子邮件的行  任何想法为什么?

<?php

$params = array(
    'to' => 'admin@mail.com', 
    'from' => '<noreply@mail.com>' 
);

$name = trim( $_POST['name'] );
$email = trim( $_POST['email'] );
$subject = trim( $_POST['subject'] );
$message = trim( $_POST['message'] );

if ( empty( $name ) or empty( $message ) ) {
    echo json_encode( array( 'status' => 'error' ) );
} else if ( empty( $email ) or ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
    echo json_encode( array( 'status' => 'email' ) );
} else {
    $headers = 'From: ' . $name . ' ' . $params['from'] . "\r\n" .
    'Reply-To: ' . $email . "\r\n" .
    'X-Mailer: PHP/' . phpversion( );
    $message = str_replace( array( "\r", "\n" ), array( '', "\r\n" ), $message );

    if ( mail( $params['to'], ( empty( $subject ) ? 'New message without subject' : 'New message: ' . $subject ), $message, $headers ) ) {
        echo json_encode( array( 'status' => 'ok' ) );
    } else {
        echo json_encode( array( 'status' => 'error' ) );
    }
}
?>

3 个答案:

答案 0 :(得分:0)

从结尾删除一个并尝试一下。 if ( mail( $params['to'], ( empty( $subject ) ? 'New message without subject' : 'New message: ' . $subject ), $message, $headers ){

答案 1 :(得分:0)

尝试引用“”不是''

$params = array(
    "to" => "admin@mail.com", 
    "from" => "<noreply@mail.com>"
);

答案 2 :(得分:0)

问题是文件的权限需要为6 4 4