简体   繁体   中英

PHP mail function not working 500 internal error

Why I cannot use the following php file. My hosting use windows host. It has 500 internal error when submit. But i can submit it in another server. I appreciate if anyone can help me.

<?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');
";


?> 

You have a "; at the end of the file which results in a parse error:

Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN)

Try removing that.

You have lots of garbage code I can see... Use this method to send email.

Also look for PHP errors by using error_reporting(E_ALL); or check Apache error logs

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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