[英]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.