PHP mail() function not sending email

前端 未结 3 1894
忘了有多久
忘了有多久 2021-01-07 10:11

I am attempting to send an email using the mail() PHP function. I had it working until I attempted to give it a subject of \"User registration\", t

3条回答
  •  灰色年华
    2021-01-07 10:32

    On your 4th line you're using ' that handles everything inside of it as a string so change

    $headers .= 'Content-type: text/html; chareset=iso-8859-1\r\n';
    

    To:

    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    

    and as mentioned in the comments change chareset to charset

    Edit:

    if your sending a txt/html mail you have according to documentation to set mime in the headers too so try this

        $to = $this->post_data['register-email'];
        $message = 'Hello etc';
    
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= 'From: Website ' . "\r\n";
        mail($to, 'User Registration', $message, $headers);
    

    If it still doesn't work you could try to debugg your code, simply add

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    on top of the page, and take it from there, and if you still can't solve it by yourself post it here and I'll do my best to help ya out.

提交回复
热议问题