繁体   English   中英

PHP邮件功能不起作用500内部错误

[英]PHP mail function not working 500 internal error

为什么我不能使用以下php文件。 我的托管使用Windows托管。 提交时有500个内部错误。 但是我可以在另一台服务器上提交它。 我感谢有人能帮助我。

<?php
header('Content-Type: text/html; charset=utf8');
if(!isset($_POST['submit']))
{

}

$name_c = $_POST['name_c'];
$name_e = $_POST['name_e'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];






$email_from = 'reg@email.com';//<== update the email address
$email_subject = 'New Form submission';
$email_body = "INfo: <br>
name: $name_c.<br>";


$to = "myemail@email.com";//<== update the email address

//$headers = "From: Me \r\n";
//$headers .= "Reply-To: $email_from \r\n";
$sCharset = 'utf-8';
$headers = "Content-type: text/html; charset=$sCharset\r\n" .
"From: Fuzinewsletter \r\n" .
"Reply-To: $email_from \r\n";


//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
";


?> 

您在文件末尾有一个";这会导致解析错误:

解析错误:语法错误,文件意外结束,预期变量(T_VARIABLE)或$ {(T_DOLLAR_OPEN_CURLY_BRACES)或{$(T_CURLY_OPEN)

尝试删除它。

您可以看到很多垃圾代码...使用此方法发送电子邮件。

也可以使用error_reporting(E_ALL);查找PHP错误error_reporting(E_ALL); 或检查Apache错误日志

function sendMail($email, $subject, $message)
{
    $supportEmail = 'info@abc.com';
    $from = 'Abc';
    $msg  = $message;
    $from = str_replace(' ', '-', $from);
    $frm  = $from.' <'.$supportEmail.'>';
    preg_match("<(.*)@(.*\..*)>", $frm, $match);

    ///////////////////Headers/////////////////
    $hdr='';
    $hdr.='MIME-Version: 1.0'."\n";
    $hdr.='content-type: text/html; charset=iso-8859-1'."\n";
    $hdr.="From: {$frm}\n";
    $hdr.="Reply-To: {$frm}\n";
    $hdr.="Message-ID: <".time()."@{$match[2]}>\n";
    $hdr.='X-Mailer: PHP v'.phpversion();
    $x=@mail($email, $subject, $msg, $hdr);
    if($x==0)
    {
        $email=str_replace('@','\@', $email);
        $hdr=str_replace('@','\@',$hdr);
        $x=@mail($email, $subject, $msg, $hdr);
    }
    return $x;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM