我试图让一封PHP电子邮件以HTML格式发送,但当前的电子邮件只是以代码形式发送。我一点也不确定我做错了什么。
有人看到什么吗?

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

$project_name           = $_POST['project_name'];
$title_roll             = $_POST['title_roll'];
$project_email          = $_POST['project_email'];
$project_number         = $_POST['project_number'];
$project_description    = $_POST['project_description'];
$project_source         = $_POST['project_source'];
$project_socialMedia    = $_POST['project_socialMedia'];
$project_humanTest      = $_POST['project_humanTest'];

$to = 'email';
$subject = 'Project Inquiry Form Sent';
//$message = 'FROM: '.$project_name. "<br>" . ' Email: '.$project_email. "<br>" . 'Message: '.$project_description;
//$msgcontents = "Name: $project_name<br>Email: $project_email<br>Message: $project_description";
$message = '
    <html>
    <head>
        <title>Project Inquiry Form Sent</title>
    </head>
    <body>
        <p>Hi Optimum Designs Team,</p><br>
        <p>There has been a Project submitted. Here are the details:</p><br>
        <p>Name: '. $project_name .'</p>
        <p>Name: '. $title_roll .'</p>
        <p>Name: '. $project_email .'</p>
        <p>Name: '. $project_number .'</p>
        <p>Name: '. $project_description .'</p>
        <p>Name: '. $project_source .'</p>
        <p>Name: '. $project_socialMedia .'</p><br>
        <p>Good Luck,</p>
        <p>Administration</p>
    </body>
    </html>
';
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From:' .$project_email . "\r\n";

if (!empty($project_email)) {
    if (filter_var($project_email, FILTER_VALIDATE_EMAIL)) {

        //Should also do a check on the mail function
        if (mail($to, $subject, $message, $headers)) {
            echo "Your email was sent!"; // success message
        } else {
            echo "Mail could not be sent!"; // failed message
        }

    } else {
        //Invalid email
        echo "Invalid Email, please provide a valid email address.";
    }

} else {
    echo "Email Address was not filled out.";
}

最佳答案

那是因为你的最后一个头球

$headers = 'From:' .$project_email . "\r\n";

缺少其连接
$headers .= 'From:' .$project_email . "\r\n";
         ^ right there

依次断开链环。

09-16 09:16