我正在尝试以HTML格式发送PHP电子邮件,但当前的电子邮件只是发送代码。我完全不确定我做错了什么。
有人看到了吗?
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.";
}
答案 0 :(得分:5)
那是因为你的上一个标题
$headers = 'From:' .$project_email . "\r\n";
缺少连接
$headers .= 'From:' .$project_email . "\r\n";
^ right there
反过来打破链环。