简体   繁体   English

PHP电子邮件未以html格式发送

[英]PHP email not sending in html format

I am trying to get a PHP email to send in an HTML format, but the current email is just sending in code. 我正在尝试使PHP电子邮件以HTML格式发送,但是当前电子邮件仅以代码发送。 I am not sure at all what I am doing wrong. 我完全不确定自己在做什么错。

Does anyone see anything? 有人看到吗?

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

That's because your last header 那是因为你的最后一个标题

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

is missing its concatenate 缺少其串联

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

in turn breaking the chainlink. 反过来破坏链环。

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

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